How to use the parmed.Structure function in ParmEd

To help you get started, we’ve selected a few ParmEd examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mosdef-hub / foyer / foyer / forcefield.py View on Github external
def _structure_from_residue(residue, parent_structure):
    """Convert a ParmEd Residue to an equivalent Structure."""
    structure = pmd.Structure()
    for atom in residue.atoms:
        structure.add_atom(atom, resname=residue.name, resnum=residue.number)

    for bond in parent_structure.bonds:
        if bond.atom1 in residue.atoms and bond.atom2 in residue.atoms:
            structure.bonds.append(bond)

    idx_offset = min([a.idx for a in structure])
    for atom in structure.atoms:
        atom._idx -= idx_offset

    return structure
github Autodesk / molecular-design-toolkit / moldesign / interfaces / parmed_interface.py View on Github external
def mol_to_parmed(mol):
    """ Convert MDT Molecule to parmed Structure
    Args:
        mol (moldesign.Molecule):

    Returns:
        parmed.Structure
    """
    import parmed
    struc = parmed.Structure()
    struc.title = mol.name

    pmedatoms = []
    for atom in mol.atoms:
        pmedatm = parmed.Atom(atomic_number=atom.atomic_number,
                              name=atom.name,
                              mass=atom.mass.value_in(u.dalton),
                              number=utils.if_not_none(atom.pdbindex, -1))
        pmedatm.xx, pmedatm.xy, pmedatm.xz = atom.position.value_in(u.angstrom)
        pmedatoms.append(pmedatm)
        struc.add_atom(pmedatm,
                       resname=utils.if_not_none(atom.residue.resname, 'UNL'),
                       resnum=utils.if_not_none(atom.residue.pdbindex, -1),
                       chain=utils.if_not_none(atom.chain.name, ''))

    for bond in mol.bonds:
github choderalab / openmoltools / openmoltools / forcefield_generators.py View on Github external
def createStructureFromResidue(residue):
    # Create ParmEd structure for residue.
    structure = parmed.Structure()
    for a in residue.atoms():
        if a.element is None:
            atom = parmed.ExtraPoint(name=a.name)
        else:
            atom = parmed.Atom(atomic_number=a.element.atomic_number, name=a.name, mass=a.element.mass)
        structure.add_atom(atom, residue.name, residue.index, 'A')
        atommap[a] = atom
    for a1, a2 in topology.bonds():
        structure.bonds.append(Bond(atommap[a1], atommap[a2]))

    return structure
github mosdef-hub / foyer / foyer / forcefield.py View on Github external
proper dihedrals.
        assert_improper_params : bool, optional, default=False
            If True, Foyer will exit if parameters are not found for all system
            improper dihedrals.
        combining_rule : str, optional, default='geometric'
            The combining rule of the system, stored as an attribute of the
            ParmEd structure. Accepted arguments are `geometric` and `lorentz`.
        verbose : bool, optional, default=False
            If True, Foyer will print debug-level information about notable or
            potentially problematic details it encounters.
        """
        if self.atomTypeDefinitions == {}:
            raise FoyerError('Attempting to atom-type using a force field '
                    'with no atom type defitions.')

        if not isinstance(structure, pmd.Structure):
            mb = import_('mbuild')
            if isinstance(structure, mb.Compound):
                structure = structure.to_parmed(**kwargs)

        typemap = self.run_atomtyping(structure, use_residue_map=use_residue_map, **kwargs)

        self._apply_typemap(structure, typemap)

        return self.parametrize_system(structure=structure,
            references_file=references_file, assert_bond_params=assert_bond_params,
            assert_angle_params=assert_angle_params, assert_dihedral_params=assert_dihedral_params,
            assert_improper_params=assert_improper_params, combining_rule=combining_rule,
            verbose=verbose, *args, **kwargs)
github mosdef-hub / foyer / foyer / forcefield.py View on Github external
for doi, atomtypes in unique_references.items():
                url = "http://api.crossref.org/works/{}/transform/application/x-bibtex".format(doi)
                headers = {"accept": "application/x-bibtex"}
                bibtex_ref = get_ref(url, headers=headers)
                if bibtex_ref is None:
                    warnings.warn('Could not get ref for doi'.format(doi))
                    continue
                else:
                    bibtex_text = bibtex_ref.text
                note = (',\n\tnote = {Parameters for atom types: ' +
                        ', '.join(sorted(atomtypes)) + '}')
                bibtex_text = bibtex_text[:-2] + note + bibtex_text[-2:]
                f.write('{}\n'.format(bibtex_text))


pmd.Structure.write_foyer = write_foyer
github Autodesk / molecular-design-toolkit / moldesign / forcefields / ffparams.py View on Github external
def __init__(self, mol, ffobj):
        import parmed

        self.mol = mol

        if isinstance(ffobj, parmed.Structure):
            self.parmed_obj = copy.copy(ffobj)
            self.sourcedata = ffobj
        elif hasattr(ffobj, 'to_parmed'):
            self.sourcedata = ffobj
            self.parmed_obj = ffobj.to_parmed()
        else:
            raise ValueError('Unrecognized force field class "%s"' % ffobj.__class__.__name__)