Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PlumedForce does not recognize continuation lines #74

Open
varun-go opened this issue Nov 11, 2023 · 3 comments
Open

PlumedForce does not recognize continuation lines #74

varun-go opened this issue Nov 11, 2023 · 3 comments

Comments

@varun-go
Copy link

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 #27 (comment)

@peastman
Copy link
Member

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:

if(apiVersion > 7) {
plumed_cmd(plumedmain, "readInputLines", force.getScript().c_str());
} else {
// NOTE: the comments and line continuation does not works
// (https://github.com/plumed/plumed2/issues/571)
// TODO: remove this when PLUMED 2.6 support is dropped
vector<char> scriptChars(force.getScript().size()+1);
strcpy(&scriptChars[0], force.getScript().c_str());
char* line = strtok(&scriptChars[0], "\r\n");
while (line != NULL) {
plumed_cmd(plumedmain, "readInputLine", line);
line = strtok(NULL, "\r\n");
}
}

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
Copy link
Author

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
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants