openmm / openmm-plumed

OpenMM plugin to interface with PLUMED
55 stars 23 forks source link

add isScriptFile argument to allow continuation lines #27

Closed tonigi closed 3 years ago

tonigi commented 4 years ago

Here I added a flag to load the whole script file (as opposed as script text). This is a strategy to allow continuation lines (which don't work when loading script line-wise) https://github.com/openmm/openmm-plumed/issues/19 .

peastman commented 4 years ago

This is a strategy to allow continuation lines (which don't work when loading script line-wise) #19 .

Could you explain? I'm not sure what that means.

tonigi commented 4 years ago

I meant that issue https://github.com/openmm/openmm-plumed/issues/19 is still open: using the readInputLine PLUMED API call bypasses the part of the PLUMED input parser which deals with continuation lines. This affects pretty much any non-trivial script.

Barring a change in the API, there are two possible solutions:

  1. duplicate the continuation-line-merging code in OpenMM, so that statements are reconstructed before passing (IMHO inelegant)
  2. create a flag in PlumedForce constructor that, when enabled, interprets the argument as a script file name, instead of script text, and uses the corresponding read API, which deals with continuation lines.

My patch implements 2 because, in addition to providing a way to deal with continuation lines, seemed a convenient feature per se.

peastman commented 4 years ago

I think this is a bug in PLUMED. When the feature to allow passing a script directly was added, the intention was that it should accept exactly the same script that would be read from the file. If it doesn't, I think the correct solution is to fix the PLUMED code.

raimis commented 4 years ago

I have hit the same issue. In addition to the line continuation, the comments do not work too.

I agree with @peastman, this is a PLUMED bug and should be fixed there. I don't see an issue about this in https://github.com/plumed/plumed2, so it is time to create the one.

raimis commented 4 years ago

Created the issue: https://github.com/plumed/plumed2/issues/571

varun-go commented 8 months ago

Openmm-plumed version (via conda forge): 1.0 Plumed version (built from source): 2.9.0
Plumed installed via conda was removed as per issue #66, as I needed to build plumed with the annfunc module.

I have an implementation question regarding continuation lines. I have a string for the plumed script, which contains continuation lines. However, when I pass this string as an argument to PlumedForce, I get the same error pointed out in issue #19. Is there an issue with my implementation? Thank you.


plumed_force_string = '''        
com_1: COM ATOMS=1,5,7,9,15,17,19
p_com: POSITION ATOM=com_1
p_0: POSITION ATOM=1
<more p_ variables>
l_0_out_0: COMBINE PERIODIC=NO COEFFICIENTS=2.000000,-2.000000 ARG=p_0.x,p_com.x
<more l_0_out variables>
ann_force: ANN ...
ARG=l_0_out_0,l_0_out_1,l_0_out_2,l_0_out_3,l_0_out_4,l_0_out_5,l_0_out_6,l_0_out_7,l_0_out_8,l_0_out_9,l_0_out_10,l_0_out_11,l_0_out_12,l_0_out_13,l_0_out_14,l_0_out_15,l_0_out_16,l_0_out_17,l_0_out_18,l_0_out_19,l_0_out_20
NUM_LAYERS=3
NUM_NODES=21,40,2
ACTIVATIONS=Tanh,Tanh
WEIGHTS0=<numbers separated by commas>
WEIGHTS2=<numbers separated by commas>
BIASES1= <numbers separated by commas>
BIASES2= <numbers separated by commas>
...
metad: METAD ...
    ARG=ann_force.node-0,ann_force.node-1
    PACE=500
    HEIGHT=1.200000
    SIGMA=0.3,0.3
    FILE=mtd_hills.txt
    TEMP=300
    BIASFACTOR=10.000000
...
PRINT ...
    STRIDE=10
    ARG=ann_force.node-0,ann_force.node-1,metad.bias
    FILE=mtd_colvar.txt
...
DUMPMASSCHARGE FILE=plumed_mc.txt'''

system.addForce(PlumedForce(plumed_force_string))

I have not displayed some sections of the script for brevity.

The error I receive is:

PLUMED: Maybe a missing space or a typo?
PLUMED: 
PLUMED: ################################################################################
PLUMED: 
Traceback (most recent call last):
  File "/home/sarupria/gopal145/miniconda3/envs/mesa-plumed-source/lib/python3.10/pdb.py", line 1726, in main
    pdb._runscript(mainpyfile)
  File "/home/sarupria/gopal145/miniconda3/envs/mesa-plumed-source/lib/python3.10/pdb.py", line 1586, in _runscript
    self.run(statement)
  File "/home/sarupria/gopal145/miniconda3/envs/mesa-plumed-source/lib/python3.10/bdb.py", line 597, in run
    exec(cmd, globals, locals)
  File "<string>", line 1, in <module>
  File "/scratch.global/gopal145/mesa_on_surfaces/MD_simulation_on_alanine_dipeptide/current_work/target/ala_dip_water_metad/openmm_metad_terminalae_cvs/run_simulation_metad.py", line 155, in <module>
    simulation = Simulation(top.topology, system, integrator,platform)
  File "/home/sarupria/gopal145/miniconda3/envs/mesa-plumed-source/lib/python3.10/site-packages/openmm/app/simulation.py", line 101, in __init__
    self.context = mm.Context(self.system, self.integrator, platform)
  File "/home/sarupria/gopal145/miniconda3/envs/mesa-plumed-source/lib/python3.10/site-packages/openmm/openmm.py", line 3749, in __init__
    _openmm.Context_swiginit(self, _openmm.new_Context(*args))
openmm.OpenMMException: 
+++ PLUMED error
+++ at PlumedMain.cpp:706, function void PLMD::PlumedMain::readInputWords(const std::vector<std::__cxx11::basic_string<char> >&)

In the ouput, the error message is repeated after every instance where line continuation was used.