Ejemplo n.º 1
0
 def testWriteCharmm27Top(self):
     """ Tests writing a Gromacs topology file with CHARMM 27 FF """
     top = load_file(get_fn('1aki.charmm27.top'))
     self.assertEqual(top.combining_rule, 'lorentz')
     GromacsTopologyFile.write(top,
             get_fn('1aki.charmm27.top', written=True))
     top2 = load_file(get_fn('1aki.charmm27.top', written=True))
     self._charmm27_checks(top)
Ejemplo n.º 2
0
 def test_write_amber99SBILDN(self):
     """ Tests writing a Gromacs topology with multiple molecules """
     top = load_file(get_fn('ildn.solv.top'))
     self.assertEqual(top.combining_rule, 'lorentz')
     fn = get_fn('ildn.solv.top', written=True)
     GromacsTopologyFile.write(top, fn, combine=None)
     top2 = load_file(fn)
     self._check_ff99sbildn(top2)
     self._check_equal_structures(top, top2)
Ejemplo n.º 3
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
Ejemplo n.º 4
0
 def testDuplicateSystemNames(self):
     """ Tests that Gromacs topologies never have duplicate moleculetypes """
     parm = load_file(get_fn('phenol.prmtop'))
     parm = parm * 20 + load_file(get_fn('biphenyl.prmtop')) * 20
     top = GromacsTopologyFile.from_structure(parm)
     self.assertEqual(top.combining_rule, 'lorentz')
     top.write(get_fn('phenol_biphenyl.top', written=True))
     top2 = GromacsTopologyFile(get_fn('phenol_biphenyl.top', written=True))
     self.assertEqual(len(top.residues), 40)
Ejemplo n.º 5
0
    def _amber_to_gromacs(self):

        # Load prmtop and inpcrd as a Structure
        parmstruct = load_file(self.outprefix + ".prmtop",
                               xyz=self.outprefix + ".inpcrd",
                               structure=True)

        # Save .gro coordinate file
        GromacsGroFile.write(struct=parmstruct, dest=self.outprefix + ".gro")

        # Save .top topology and parameter file
        grotop = GromacsTopologyFile.from_structure(parmstruct, copy=False)
        grotop.write(dest=self.outprefix + ".top", parameters="inline")
Ejemplo n.º 6
0
def to_parmed_GromacsTopologyFile(item, atom_indices='all', check=True):

    if check:

        digest_item(item, 'parmed.Structure')
        atom_indices = digest_atom_indices(atom_indices)

    from . import extract
    from parmed.gromacs import GromacsTopologyFile as GromacsTopologyFile

    tmp_item = extract(item,
                       atom_indices=atom_indices,
                       copy_if_all=False,
                       check=False)
    tmp_item = GromacsTopologyFile.from_structure(tmp_item)

    return tmp_item
Ejemplo n.º 7
0
def to_parmed_GromacsTopologyFile(item,
                                  molecular_system=None,
                                  atom_indices='all',
                                  structure_indices='all'):

    from parmed.gromacs import GromacsTopologyFile
    from molsysmt.api_forms.api_parmed_GromacsTopologyFile import to_parmed_GromacsTopologyFile as parmed_GromacsTopologyFile_to_parmed_GromacsTopologyFile

    tmp_item = GromacsTopologyFile(item)
    if molecular_system is not None:
        tmp_molecular_system = molecular_system.combine_with_items(tmp_item)
    else:
        tmp_molecular_system = None
    tmp_item = parmed_GromacsTopologyFile_to_parmed_GromacsTopologyFile(
        tmp_item,
        molecular_system=tmp_molecular_system,
        atom_indices=atom_indices,
        structure_indices=structure_indices,
        copy_if_all=False)

    return tmp_item, tmp_molecular_system