Skip to content

Commit 56890ad

Browse files
committed
parse forces
1 parent fcce6ac commit 56890ad

File tree

1 file changed

+91
-3
lines changed

1 file changed

+91
-3
lines changed

vmdplumed.tcl

Lines changed: 91 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1932,9 +1932,9 @@ proc ::Plumed::do_compute {{outfile ""}} {
19321932
if {$plumed_version==1} { cd_push $tmpd }
19331933
if { [ catch { exec {*}$cmd } driver_stdout ] ||
19341934
! [file readable $colvar] } {
1935-
set dontplot 1
1935+
set failure 1
19361936
} else {
1937-
set dontplot 0
1937+
set failure 0
19381938
}
19391939
if {$plumed_version==1} { cd_push - }
19401940

@@ -1944,7 +1944,7 @@ proc ::Plumed::do_compute {{outfile ""}} {
19441944
puts "Temporary files are in directory $tmpd"
19451945

19461946
# Parse if v2
1947-
if { $dontplot } {
1947+
if { $failure } {
19481948
puts "Something went wrong. Check above messages."
19491949
tk_messageBox -icon error -title "Error" -parent .plumed -message \
19501950
"PLUMED returned an error while executing the script. Please find error messages in the console. "
@@ -2107,6 +2107,94 @@ proc ::Plumed::get_pbc_v2 { } {
21072107
}
21082108

21092109

2110+
# Run driver with --dump-forces. Extensive refactoring needed.
2111+
proc ::Plumed::do_compute_forces_v2 { } {
2112+
variable driver_path
2113+
2114+
if {[molinfo top]==-1 || [molinfo top get numframes] < 1} {
2115+
tk_messageBox -title "Error" -icon error -parent .plumed -message \
2116+
"A top molecule and at least one frame is required to plot."
2117+
return
2118+
}
2119+
2120+
if {![file executable $driver_path]} {
2121+
tk_messageBox -title "Error" -icon error -parent .plumed -message \
2122+
"The plumed executable is required. See manual for installation instructions."
2123+
return }
2124+
2125+
# Prepare temp. dir and files
2126+
set tmpd [file join [tmpdir] vmdplumed.[pid]]
2127+
file mkdir $tmpd
2128+
2129+
set meta [file join $tmpd META_INP]
2130+
set pdb [file join $tmpd temp.pdb]
2131+
set dcd [file join $tmpd temp.dcd]
2132+
set colvar [file join $tmpd COLVAR]
2133+
set forces [file join $tmpd FORCES]
2134+
2135+
writePlumed [atomselect top all] $pdb
2136+
animate write dcd $dcd waitfor all
2137+
file delete $colvar
2138+
2139+
write_meta_inp_v2 $meta $colvar
2140+
set pbc [get_pbc_v2]
2141+
set cmd [list $driver_path --standalone-executable driver {*}$pbc --mf_dcd $dcd --pdb $pdb --plumed $meta --dump-forces $forces ]
2142+
2143+
puts "Executing: $cmd"
2144+
2145+
if { [ catch { exec {*}$cmd } driver_stdout ] ||
2146+
! [file readable $colvar] } {
2147+
set failure 1
2148+
} else {
2149+
set failure 0
2150+
}
2151+
2152+
2153+
# Results
2154+
puts $driver_stdout
2155+
puts "-----------"
2156+
puts "Temporary files are in directory $tmpd"
2157+
2158+
# Parse if v2
2159+
if { $failure } {
2160+
puts "Something went wrong. Check above messages."
2161+
tk_messageBox -icon error -title "Error" -parent .plumed -message \
2162+
"PLUMED returned an error while executing the script. Please find error messages in the console. "
2163+
return
2164+
}
2165+
2166+
set force_list [parse_forces $forces]
2167+
return $force_list
2168+
}
2169+
2170+
# Parse a forces file like
2171+
# NATOMS
2172+
# FBX FBY FBZ
2173+
# X F1X F1Y F1Z
2174+
# X ...
2175+
# repeated for a number of frames. Return a list of lists
2176+
proc ::Plumed::parse_forces {forces} {
2177+
set ff [open $forces r]
2178+
set force_list {}
2179+
while {[gets $ff nat]>=0} {
2180+
gets $ff boxforces
2181+
set this_frame_forces {}
2182+
for {set a 0} {$a < $nat} {incr a} {
2183+
# Delete atom name
2184+
gets $ff line
2185+
set fxyz [lreplace $line 0 0]
2186+
lappend this_frame_forces $fxyz
2187+
}
2188+
lappend force_list $this_frame_forces
2189+
}
2190+
close $ff
2191+
return $force_list
2192+
}
2193+
2194+
2195+
2196+
2197+
21102198
# ==================================================
21112199
# VMDCV-specific stuff
21122200

0 commit comments

Comments
 (0)