forked from CG-it/CG-it
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cgit.tcl
477 lines (374 loc) · 15.1 KB
/
cgit.tcl
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
#!/usr/bin/tclsh
# +-------+
# | CG-it |
# +-------+
# CG-it, a VMD package to simplify creating coarse grained SDK
# topologies.
# Copyright (c) 2013 by Chris MacDermaid <chris.macdermaid@gmail.com>
# and Giacomo Fiorin <giacomo.fiorin@gmail.com>
#(Shinoda) Shinoda, DeVane, Klein, Mol Sim, 33, 27 (2007).
#(DeVane) Shinoda, DeVane, Klein, Soft Matter, 4, 2453-2462 (2008).
## None of this will work without topotools.
package require topotools
## This package makes extensive use of some Tcl 8.5 features.
package require Tcl 8.5
namespace eval ::CGit:: {
namespace export CGit
variable version 1.1
## Valid cgit commands
variable validcmd {readtop readparam reanalyzemol setbonds
setangles setdihedrals setimpropers reset clear readlammpsdata writelammpsdata
writelammpsparam writesdktopo writetop setbondparam setangleparam
setpairparam deletebondparam deleteangleparam deletepairparam getbondparam
getangleparam getpairparam readmap map maptrajectory maptraj
printmap setparam deleteparam getparam printparam printmaptable
printmap solvate help commands topo2map}
## Parameter Files loaded by default
variable param_files {param_sdk.dat}
## Parameter array
#variable params
#array set params {}
#array unset params *
#Parameter Dictionary
variable params ""
## Store interface variables
variable sys
array unset sys
## Atom Mappings and Topologies
variable map ""
## Test map internal consistency on loading?
variable maptest 0
## Show the title and citation info?
variable showtitle 0
## Locations of additional data files
variable datadir $env(CGITDIR)
## Make some utility commands accessable
namespace export map map_trajectory
## Return error codes
set sys(OK) 0
set sys(ERROR) -1
}
# +----------------+
# | Global command |
# +----------------+
proc CGit { args } {
eval ::CGit::CGit $args
}
proc CGit::title {} {
variable version
cgCon -info "CG-it Version $version "
cgCon -info "Loading from: [info script] "
cgCon -info "Please Cite: "
}
proc CGit::usage {} {
set groups(1) "common flags:"
set commands(1) {\
{ {-molid} {<num>|top} {molecule id (default: 'top')}}\
{ {-sel} {<selection>} {atom selection function or text (default: 'all')}}\
}
set groups(2) ""
set commands(2) {\
{ {help} {} {prints this message}}\
}
set groups(3) "Topologies and Parameters:"
set commands(3) {\
{ {readtop} {<filename>} {read topology file}}\
{ {readparam} {<filename>} {read parameter file}}\
{ {writetop} {[<filename>]} {write legacy SDK topology for specified selection}}\
{ {topo2map} {<topfile> [<mapfile>]} {convert legacy SDK topology to map}}\
{ {printparam} {} {print to screen all currently loaded parameters}}\
{ {clear} {<maps> <params> <both>} {clear the all maps, params or both}}\
{ {reset} {} {clear loaded parameters and topologies, reload defaults}}\
{ {} {} {}}\
{ {(set|delete)bondparam} {<type1> <type2>} {re/set bond parameters for specified atom types}}\
{ {} {<k> <r_bond>} {}}\
{ {(set|delete)angleparam} {<type1> <type2> <type3>} {re/set angle parameters for specified atom types}}\
{ {} {<k> <theta>} {}}\
{ {(set|delete)pairparam} {<type1> <type2> <lj_type>} {re/set pair parameters for specified atom types}}\
{ {} {<epsilon> <sigma>} {}}\
{ {} {} {}}\
{ {get(bond|angle|pair)param} {} {print specified parameters. Wildcard '*' returns }}\
{ {} {<type1> <type2> [<type3> <type4>]} {all types: e.g. 'cg getbondparam PH *'}}\
}
set groups(4) "CG mappings:"
set commands(4) {\
{ {readmap} {<filename>} {read an SDK map file}}\
{ {map} {} {perfrom a CG mapping}}\
{ {maptraj} {[<start> <end> <skip>]} {perfrom a CG mapping of a trajectory}}\
{ {printmap} {<resname>} {print out mapping information for specified}}\
{ {} {} {residue name (default 'all')}}\
}
set groups(5) "Molecule Preparation:"
set commands(5) {\
{ {set(bonds|angles|dihedrals|impropers)} {} {Apply bonding/angle connectivities specified from}}\
{ {} {} {topologies/maps to selected atoms.}}\
{ {reanalyzemol} {} {Apply [<mass> <charge> <index> <type> <all> <none>] properties}}\
{ {} {} {from topologies to selected atoms and retype}}\
{ {} {} {[<bonds> <angles> <dihedrals> <impropers>] (default 'all bonds angles')}}\
{ {solvate} {[<distance> <filename>]} {Solvate selected atoms in a solvent box according}}\
{ {} {} {to pbc cell size with a minimum <distance> (default '3')}}\
{ {} {} {angstroms from the solute. <filename> specifies a pdb file}}\
{ {} {} {for a orthorhombic solvent box.}}\
}
set groups(6) "LAMMPS:"
set commands(6) {\
{ {writelammpsdata} {<filename> <atomstyle>} {Write out a data file suitable for use with lammps}}\
{ {writelammpsparam} {<filename>} {Write out a lammps SDK 'parameter' file containing}}\
{ {} {(cpu|gpu|both)} {forcefield parameters required by the system. Compatible}}\
{ {} {} {options for simulating with <cpu> <gpu> or <both> are provided}}\
{ {} {(geometric|arithmetic|lb)} {Generate missing LJ parameters with geometric,}}\
{ {} {} {arithmetic, or Lorentz-Berthelot rules}}\
}
cgCon -info "usage: cg <command> \[args...\] <flags>"
cgCon -info "Note: by default, cgit works on all atoms in the top molecule"
cgCon -info ""
## Print out each group
foreach g {2 1 3 4 5 6} {
cgCon -info $groups($g)
foreach cmd $commands($g) {cgCon -info [format " %-15s %-25s %-25s" {*}$cmd]}
cgCon -info ""
}
}
# +---------------------------------------------------+
# | Parse arguments, set defaults, execute directives |
# +---------------------------------------------------+
proc CGit::CGit { args } {
variable validcmd
set molid -1
set seltxt all
set selmol -1
set localsel 1
set cmd {}
set sel {}
set newargs {}
for {set i 0} {$i < [llength $args]} {incr i} {
set arg [lindex $args $i]
if {[string match -?* $arg]} {
set val [lindex $args [expr $i+1]]
switch -- $arg {
-molid {
if {[catch {molinfo $val get name} res]} {
cgCon -err "Invalid -molid argument '$val': $res"
return
}
set molid $val
if {[string equal $molid "top"]} {
set molid [molinfo top]
}
incr i
}
-sel {
# check if the argument to -sel is a valid atomselect command
if {([info commands $val] != "") && ([string equal -length 10 $val atomselect])} {
set localsel 0
set selmol [$val molid]
set sel $val
} else {
set localsel 1
set seltxt $val
}
incr i
}
-- break
default {
#cgCon -info "default: $arg"
lappend newargs $arg
}
}
} else {
lappend newargs $arg
}
}
if {$molid < 0} {
set molid $selmol
}
if {$molid < 0} {
set molid [molinfo top]
}
set retval ""
if {[llength $newargs] > 0} {
set cmd [lindex $newargs 0]
set newargs [lrange $newargs 1 end]
} else {
set newargs {}
set cmd help
}
if {[lsearch -exact -ascii $validcmd $cmd] < 0} {
cgCon -err "Unknown command '$cmd'"
usage
return
}
if { ![string equal $cmd help] && $molid >= 0 } {
if {($selmol >= 0) && ($selmol != $molid)} {
cgCon -err "Molid from selection '$selmol' does not match -molid argument '$molid'"
return
}
if {$localsel} {
# need to create a selection
if {[catch {atomselect $molid $seltxt} sel]} {
cgCon -err "Problem with atom selection using '$seltxt': $sel"
return
}
}
}
switch -- $cmd {
readtop {
if {[llength $newargs] < 1} {
cgCon -err "cgit 'readtop' requires a file to read from"
usage
return
}
## Convert legacy top to map on the fly
readTopo {*}$newargs
}
topo2map {
if {[llength $newargs] < 1} {
usage
return
}
set out [lindex $newargs 1]
if {$out == ""} {set out stdout}
topo2map [lindex $newargs 0] $out 0
}
writetop -
writesdktopo {
if {$sel == "" || $molid < 0} {return [usage]}
writesdktopo $sel {*}$newargs
}
readparam {
if {[llength $newargs] < 1} {
cgCon -err "cgit 'readparam' requires a file to read from"
usage
return
}
#read_param $newargs
readParam {*}$newargs
}
readlammpsdata {
if {[llength $newargs] < 1} {
cgCon -err "cgit 'readlammpsdata' requires a file to read from as argument"
usage
return
}
set retval [readlammpsdata {*}$newargs]
}
writelammpsdata {
if {[llength $newargs] < 1} {
cgCon -err "cgit 'writelammpsdata' requires a file to write to as argument"
usage
return
}
writelammpsdata $molid {*}$newargs
}
writelammpsparam {
if {[llength $newargs] < 1} {
cgCon -err "cgit 'writelammpsparam' requires a file to write to as argument"
usage
return
}
writelammpsparam $molid {*}$newargs
}
printmap -
printmaptable {map_stats {*}$newargs}
mapread -
readmap {
if {[llength $newargs] < 0} {
cgCon -err "cgit 'readmap' requires a file to read from as argument"
usage
return
}
readTopo{*}$newargs
}
map -
maptraj -
maptrajectory {
if {$sel == "" || $molid < 0} {return [usage]}
set retval [map $sel {*}$newargs]
}
setbond -
setbonds {
if {$sel == "" || $molid < 0} {return [usage]}
set_bonds $sel
}
setangle -
setangles {
if {$sel == "" || $molid < 0} {return [usage]}
set_angles $sel
}
setdihedral -
setdihedrals {
if {$sel == "" || $molid < 0} {return [usage]}
set_dihedrals $sel
}
setimproper -
setimpropers {
if {$sel == "" || $molid < 0} {return [usage]}
set_impropers $sel {*}$newargs
}
reanalyzemol {
if {$sel == "" || $molid < 0} {return [usage]}
reanalyze_mol $sel {*}$newargs
}
reset {reset}
clear {
clear {*}$newargs
}
solvate {
if {$sel == "" || $molid < 0} {return [usage]}
set retval [solvate_box $sel {*}$newargs]
}
setbondparam {set_param bond {*}$newargs}
setangleparam {set_param angle {*}$newargs}
setpairparam {set_param pair {*}$newargs}
setparam {set_param {*}$newargs}
deletebondparam {delete_param bond {*}$newargs}
deleteangleparam {delete_param angle {*}$newargs}
deletepairparam {delete_param pair {*}$newargs}
deleteparam {delete_param {*}$newargs}
getbondparam {set retval [get_param bond {*}$newargs]}
getangleparam {set retval [get_param angle {*}$newargs]}
getpairparam {set retval [get_param pair {*}$newargs]}
getparam {set retval [get_param {*}$newargs]}
printparam {print_param {*}$newargs}
commands {return [join $validcmd]}
help -
default {usage}
}
if {$localsel} {
catch {$sel delete}
}
return $retval
}
# +---------+
# | Helpers |
# +---------+
## A wrapper around cgCon
proc CGit::cgCon {flag str} {
switch -- $flag {
"-error" -
"-err" { vmdcon -err "CG> $str" }
"-warn" { vmdcon -warn "CG> $str" }
"-info" { vmdcon -info "CG> $str" }
default { vmdcon $str}
}
}
# +---------+
# | Startup |
# +---------+
interp alias {} cg {} ::CGit::CGit
package provide cg $::CGit::version
if {$::CGit::showtitle} {::CGit::title}
## Load other cgit files
#source [file join $env(CGITDIR) maps common.tcl]
source [file join $env(CGITDIR) cgit_map.tcl]
source [file join $env(CGITDIR) cgit_partopo.tcl]
source [file join $env(CGITDIR) cgit_traj.tcl]
source [file join $env(CGITDIR) cgit_lammps.tcl]
source [file join $env(CGITDIR) cgit_solvate.tcl]
source [file join $env(CGITDIR) cgit_legacy.tcl]
source [file join $env(CGITDIR) cgit_helpers.tcl]
source [file join $env(CGITDIR) json.tcl]
## C-based routines
catch {load [file join $env(CGITDIR) libcgmap.so]}
## Load the default mappings from maps in $env(CGITDIR)/maps
##::CGit::map_defaults