marrink-lab / polyply_1.0

Generate input parameters and coordinates for atomistic and coarse-grained simulations of polymers, ssDNA, and carbohydrates
Apache License 2.0
119 stars 21 forks source link

Convert itp files to ff files #327

Open fgrunewald opened 1 year ago

fgrunewald commented 1 year ago

The new utility allows users to extract ff-files automatically from itp files by defining fragments as SMILES. Currently the code only works for linear polymers. Let's look at some examples for how to use this Program.

Say we have a itp that describes any number of PEO oligomers then to extract the parameters for PEO we'd run:

polyply itp_to_ff -i <itp_file.ipt> -sm [CH2]O[CH2] -rn PEO -o new.ff -charge 0

Now of course with PEO there is the challenge of how we treat the termini. They can for example be terminated with an OH group. By default the algorithm will group all atoms that cannot be assigned to a fragment as given by the smile into the next connected fragment. Thus it creates a new bigger fragment. In this example, we would obtain the PEO fragment but also PEOter fragment that describes the termini. If they are asymmetric the code produces 2 new residues describing the termini.

Of course this might not be what we want, since we may want to build a modular ff format. In this case we can also specify the OH terminal explicitly as a fragment. For example, like so:

polyply itp_to_ff -i <itp_file.ipt> -sm [OH][CH2] [CH2]O[CH2] [OH][CH2] -rn OH PEO OH -o new.ff -charge 0

Note that we need to provide the terminal definitions on both ends, because the code works in blocks. Using this command we obtain definition for the termini as a separate block.

@ricalessandri

To Do

Known Issues

ricalessandri commented 7 months ago

@fgrunewald current version (commit a39c3acb06614d99fa6181a702e62123f823561f) gives the following error:

Traceback (most recent call last):
  File "/Users/alessandri/miniconda3/envs/itp_to_ff/bin/polyply", line 281, in <module>
    main()
  File "/Users/alessandri/miniconda3/envs/itp_to_ff/bin/polyply", line 277, in main
    subprogram(**args_dict)
TypeError: itp_to_ff() got an unexpected keyword argument 'tolerance'

with commands like:

polyply itp_to_ff -i PS_n4_AA_oplsLigParGen.itp -sm '[CH](c1ccccc1)[CH2]' -rn PS -o new_OK.ff 
fgrunewald commented 7 months ago

@ricalessandri can you try removing polyply and reinstalling? Sometimes the toplevel script points to the wrong version of the library.

ricalessandri commented 7 months ago

Just created a fresh conda environment, switched to branch, installed but still get the same. Commands:

conda create -n itp_to_ff_2  python=3
conda activate itp_to_ff_2
git clone https://github.com/marrink-lab/polyply_1.0.git
cd polyply_1.0.git
git checkout remotes/origin/itp_to_ff
git switch -c itp_to_ff
pip install -e .
pip install pytest
pip install pysmiles

These are the installed packages and versions:

Successfully installed decorator-4.4.2 networkx-2.8.8 numpy-1.26.2 pbr-6.0.0 polyply-1.5.1.dev102 scipy-1.11.4 tqdm-4.66.1 vermouth-0.9.6
Successfully installed iniconfig-2.0.0 packaging-23.2 pluggy-1.3.0 pytest-7.4.3
Successfully installed pysmiles-1.1.2

I get the same error as in the previous post.

fgrunewald commented 7 months ago

@ricalessandri should be fixed now; the problem was on my end where an old polyply was giving the correct result. I now removed the decimals option again.

ricalessandri commented 6 months ago

@fgrunewald Now the code runs fine but the charge equalization (and rounding) doesn't seem to be working for me. For example, these are the charges of a CH3 termini:

[ moleculetype ]
CH3ter 3
[ atoms ]
1 off_001 1 CH3ter C0 1 -0.089577318182 12.01078
2 off_004 1 CH3ter H1 1  0.032722681818 1.007947
3 off_004 1 CH3ter H2 1  0.032722681818 1.007947
4 off_004 1 CH3ter H3 1  0.032722681818 1.007947

with -0.089577318182+0.032722681818*3 =0.008590727271999984. Same for the block (this is polypropylene):

[ moleculetype ]
PP 3
[ atoms ]
1 off_001 1 PP C0 1 -0.065677318182 12.01078
2 off_001 1 PP C1 1 -0.090077318182 12.01078
3 off_001 1 PP C2 1 -0.075377318182 12.01078
4 off_004 1 PP H3 1  0.048722681818 1.007947
5 off_004 1 PP H4 1  0.033389681818 1.007947
6 off_004 1 PP H5 1  0.033389681818 1.007947
7 off_004 1 PP H6 1  0.033389681818 1.007947
8 off_004 1 PP H7 1  0.040722681818 1.007947
9 off_004 1 PP H8 1  0.040722681818 1.007947

total charge is -0.0007948636380000207. Also, in here you indicated rounding to at most 2 significant digits as done but this seems not to be the case.

fgrunewald commented 6 months ago

@ricalessandri can you provide the original itp-file? What are the total charges in these blocks? 2 decimals was my intended goal but that's not possible given that the charge neutrality needs to be given for systems sizing up to millions of residues

Perhaps a different optimizer yields better properties. Could you try to map out how well it works for the polymers you already have?

I should perhaps also point out that it will never yield exactly zero. With the current default settings the total charges are within the accuracy limit. I did notice though that the accuracy is not correctly propagated, which means it is hard coded at the moment.

ricalessandri commented 6 months ago

I sent the itp to you by email. I will try it out on some more examples.

fgrunewald commented 6 months ago

@ricalessandri I see what's going wrong. There is no charge balancing being done because at the moment it requires the entry point to be a toplogy file (i.e. .top). See here:

https://github.com/marrink-lab/polyply_1.0/blob/39f7ad4e9b5923c18ff8a529294cabe877b44a9c/polyply/src/itp_to_ff.py#L65-L74

You can test if it works by removing the if statement in Line 66. Otherwise, I can have a look tomorrow morning. Just note that processing itp files is at the moment pointless because charges won't get balanced.

ricalessandri commented 6 months ago

@fgrunewald Small update. I tried commenting that line out, this is the error I get:

Traceback (most recent call last):
  File "/Users/alessandri/miniconda3/envs/itp_to_ff_2/bin/polyply", line 279, in <module>
    main()
  File "/Users/alessandri/miniconda3/envs/itp_to_ff_2/bin/polyply", line 275, in main
    subprogram(**args_dict)
  File "/Users/alessandri/polyply_1.0-itp_to_ff_2/polyply/src/itp_to_ff.py", line 70, in itp_to_ff
    topology=top,
             ^^^
UnboundLocalError: cannot access local variable 'top' where it is not associated with a value

I also tried to just pass an actual top file instead of the itp file to itp_to_ff but then I get:

Traceback (most recent call last):
  File "/Users/alessandri/miniconda3/envs/itp_to_ff_2/bin/polyply", line 279, in <module>
    main()
  File "/Users/alessandri/miniconda3/envs/itp_to_ff_2/bin/polyply", line 275, in main
    subprogram(**args_dict)
  File "/Users/alessandri/polyply_1.0-itp_to_ff_2/polyply/src/itp_to_ff.py", line 39, in itp_to_ff
    mol = top.molecules[0].molecule
          ~~~~~~~~~~~~~^^^
IndexError: list index out of range
fgrunewald commented 6 months ago

@ricalessandri should be fixed, give it a try

fgrunewald commented 4 months ago

@ricalessandri that's it; except for the improvements on labeling edges the code is done and has all tests required. I ran it on my CHARMM database and will try some OPLS tomorrow. Please give it a try and see if there are any problems.