mosdef-hub / foyer

A package for atom-typing as well as applying and disseminating forcefields
https://foyer.mosdef.org
MIT License
119 stars 77 forks source link

Question on Retaining Manual Atomtype Modifications Post apply Method in Foyer #555

Closed mattiafelice-palermo closed 8 months ago

mattiafelice-palermo commented 8 months ago

Dear Foyer Development Team,

Thank you for developing Foyer, it is a really helpful tool in my work routine!

I have a question regarding a specific use case: I need to manually modify the atomtype of a particular atom in a molecule obtained from Foyer's apply method, and then rerunning the parametrization considering this change:

import mbuild as mb
import foyer

filename = "molecule.pdb"

molecule = mb.load(filename)
ff = foyer.Forcefield(name="oplsaa")

mol_ff = ff.apply(molecule)

for atom in mol_ff:
    if atom.idx in [4, 44, 53]:
        atom.type = "opls_158"

new_ff = ff.apply(mol_ff)

However, when I manually modify the atomtype in the generated ParmEd structure and rerun apply giving the newly modified structure as input, the original atomtypes are reassigned, ignoring my changes.

Is there a way to achieve this in Foyer, or does it fall outside its intended functionality?

Apologies if this seems trivial; I've been trying to find a solution without success.

Kind regards,

Mattia

daico007 commented 8 months ago

Hi @mattiafelice-palermo, the behavior you're seeing there is because when you re-run the apply step, the atomtype map is regenerated and overwrite the modification you're done above. Furthermore, they way you're modifying the mol_ff object only changed the name of the atomtype, but not the charge or parameters associated with it. I am guess you're rerunning the apply step to get the updated bond/angle/dihedral type? If that's the case, I think it may be better to modify the opls.xml (a local version for your project) to update the override/smarts string of opls_158 to overwrite whatever atomtype was assigned there in the first place.

mattiafelice-palermo commented 8 months ago

Eventually I moved on doing exactly as you suggested :) Thank you for the help!