Skip to content
New issue

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

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

Already on GitHub? # to your account

Is it possible to combine multiple forcefields to parametrise the same molecule? #594

Open
iGulitch opened this issue Nov 25, 2024 · 1 comment

Comments

@iGulitch
Copy link

In principle, the question is formulated in the header. What I mean is if it's possible to use two different xml files [ that hopefully have no conflicts ] to define a force-field for the same molecule? I'm interested since on top of the default oplsaa.xml I might have some add-ons that I would like to use without modifying the original file.

@CalCraven
Copy link
Contributor

Hey @iGulitch. You can't use two forcefields on the same molecule currently, but you could use two forcefields each on their own molecule that you specify with the molecule name. The function you need lives in GMSO. Note the text defining the forcefields argument, which can take a dictionary. We intend to include residue matching for forcefields using the same API, but haven't quite determined a consistent way to handle connections that would occur between residues.

If you have two forcefields xmls, and want to combine them into a single forcefield, here's a script that should work:

import gmso
ff1 = gmso.ForceField("path_to_xml1.xml")
ff2 = gmso.ForceField("path_to_xml2.xml")
ff1.atom_types.update(ff2.atom_types) # this will overwrite atomtypes that have the same name in ff1. Use this with care
for ff_attr in ["bond", "angle", "dihedral", "improper"]:
    gettattr(ff1, ff_attr).update(getattr(ff2, ff_attr) # i.e.   ff1.bond_types.update(ff2.bond_types)
    # same warnings apply
ff1.to_xml("updated_name.xml")

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

No branches or pull requests

2 participants