openmm / openmm-plumed

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

PlumedForce does not recognize continuation lines #74

Open varun-go opened 7 months ago

varun-go commented 7 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.

Originally posted by @varun-go in https://github.com/openmm/openmm-plumed/issues/27#issuecomment-1806148709

peastman commented 7 months ago

This ought to work correctly if you have the latest versions of PLUMED and OpenMM-PLUMED. Here's the code where it reads the input file:

https://github.com/openmm/openmm-plumed/blob/66873f73de0350c98b24b19f8a5ba0572b74f71b/platforms/reference/src/ReferencePlumedKernels.cpp#L96-L109

That's the reference platform version. There's similar code for the other platforms. If it's a sufficiently recent version of PLUMED, it calls readInputLines which supports continuations. Otherwise it has to read lines one at a time with readInputLine, which doesn't.

Can you compile OpenMM-PLUMED from source and have it print out the value of apiVersion?

varun-go commented 7 months ago

Thank you for the response. I am currently resolving some issues compiling OpenMM-PLUMED from source, so I will check this as soon as it is fixed. However, I tried searching for the cpp file in the conda environment that has OpenMM-PLUMED, and I could not find it.

peastman commented 7 months ago

I don't think conda installs the source code, just the compiled library.