Exemple #1
0
def apply_forcefield(structure, forcefield, debug=False):
    """Apply a forcefield to a Topology. """
    if not structure.bonds:
        warn("Structure contains no bonds: \n{}\n".format(structure))
    if isinstance(forcefield, string_types):
        if forcefield.lower() in ["opls-aa", "oplsaa", "opls"]:
            if os.path.isdir("oplsaa.ff"):
                ff_path = "oplsaa.ff/forcefield.itp"
            else:
                ff_path = os.path.join(gmx.GROMACS_TOPDIR, "oplsaa.ff/forcefield.itp")
        elif forcefield.lower() in ["trappeua"]:
            ff_path = os.path.join(gmx.GROMACS_TOPDIR, "trappeua.ff/forcefield.itp")
        else:
            ff_path = forcefield
            # TODO: this is a patchwork fix until rules and FF files become one
            forcefield = forcefield.lower()
            for alias in OPLS_ALIASES:
                if alias in forcefield:
                    forcefield = "oplsaa"
        ff = GromacsTopologyFile(ff_path, parametrize=False)

    find_atomtypes(structure.atoms, forcefield, debug=debug)

    if hasattr(structure, "box"):
        ff.box = structure.box
    ff.atoms = structure.atoms
    ff.bonds = structure.bonds
    ff.residues = structure.residues
    create_bonded_forces(ff)
    ff.parametrize()
    return ff