-
Notifications
You must be signed in to change notification settings - Fork 0
/
top2psf.jl
68 lines (58 loc) · 1.56 KB
/
top2psf.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
using ArgParse
function top2psf(top, psf)
# converts crawler.jl topology to a minimal psf topology file that VMD can read
bondIdx = []
open(top, "r") do top
contents = readlines(top)
i = 1
while i <= length(contents)
if occursin("<bonds>", contents[i])
i += 1
while !occursin("<end>", contents[i])
bondContents = split(contents[i], " ")
bond1 = parse(Int64, bondContents[1])
bond2 = parse(Int64, bondContents[2])
bondLength = parse(Float64, bondContents[3])
bondK = parse(Float64, bondContents[4])
push!(bondIdx, [bond1, bond2])
i += 1
end
end
i += 1
end
end
nAtoms = maximum(hcat(bondIdx...)')
nBonds = size(bondIdx, 1)
open(psf, "w+") do top
write(top, "PSF\n")
write(top, " 0 !NTITLE\n")
write(top, " $(nAtoms) !NATOM\n")
for i in 1:nAtoms
write(top, " $(i) MAIN 1 X C C 0.000000 0.00000 0\n")
end
write(top, "\n")
write(top, " $(nBonds) !NBOND: bonds\n")
write(top, " ")
for i in 1:nBonds
# 1 and 2 digit numbers only for now
write(top, "$(bondIdx[i][1])")
write(top, repeat(" ", 7 - length("$(bondIdx[i][1])")))
write(top, "$(bondIdx[i][2])")
write(top, repeat(" ", 7 - length("$(bondIdx[i][2])")))
if i % 4 == 0
write(top, "\n ")
end
end
end
end
argTable = ArgParseSettings()
@add_arg_table argTable begin
"topology"
arg_type = String
required = true
"psf"
arg_type = String
required = true
end
args = parse_args(argTable)
top2psf(args["topology"], args["psf"])