How to use the parmed.openmm 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 openforcefield / smarty / examples / testing / mergeff / mergeff.py View on Github external
gaff_xml_filename = openmoltools.utils.get_data_filename("parameters/gaff.xml")
    forcefield = app.ForceField('amber99sbildn.xml', 'tip3p.xml', gaff_xml_filename)
    forcefield.registerTemplateGenerator(forcefield_generators.gaffTemplateGenerator)

    #Setup proteim
    modeller = app.Modeller(pdbfile.topology, pdbfile.positions)
    modeller.addHydrogens(forcefield, pH=7.0)

    ###Solvate and Ionize...?

    #Generate OpenMM system with FF parameters
    topology = modeller.getTopology()
    system = forcefield.createSystem( modeller.getTopology() )

    #Load System to ParmEd Structure
    structure = pmd.openmm.load_topology(topology, system)

    return structure
github mosdef-hub / foyer / foyer / forcefield.py View on Github external
references_file=None, assert_bond_params=True,
                           assert_angle_params=True,
                           assert_dihedral_params=True,
                           assert_improper_params=False,
                           combining_rule='geometric', verbose=False,
                           *args, **kwargs):

        topology, positions = _topology_from_parmed(structure, self.non_element_types)

        system = self.createSystem(topology, *args, **kwargs)

        _separate_urey_bradleys(system, topology)

        data = self._SystemData

        structure = pmd.openmm.load_topology(topology=topology, system=system)
        structure.bonds.sort(key=lambda x: x.atom1.idx)
        structure.positions = positions
        box_vectors = topology.getPeriodicBoxVectors()
        if box_vectors is not None:
            structure.box_vectors = box_vectors

        _check_bonds(data, structure, assert_bond_params)
        _check_angles(data, structure, verbose, assert_angle_params)
        _check_dihedrals(data, structure, verbose,
                              assert_dihedral_params, assert_improper_params)

        if references_file:
            atom_types = set(atom.type for atom in structure.atoms)
            self._write_references_to_file(atom_types, references_file)

        # TODO: Check against the name of the force field and/or store
github MobleyLab / blues / blues / utils.py View on Github external
- Amber ASCII restart (.rst7/.inpcrd/.restrt, rst7)
        - Amber NetCDF restart (.ncrst, ncrst)

    """
    system = context.getSystem()
    state = context.getState(
        getPositions=True,
        getVelocities=True,
        getParameters=True,
        getForces=True,
        getParameterDerivatives=True,
        getEnergy=True,
        enforcePeriodicBox=True)

    # Generate the ParmEd Structure
    structure = parmed.openmm.load_topology(topology, system, xyz=state.getPositions())

    structure.save(outfname, overwrite=True)
    logger.info('\tSaving Frame to: %s' % outfname)
github choderalab / perses / perses / rjmc / geometry.py View on Github external
Arguments
        ----------
        top_proposal : TopologyProposal object
            Object containing the relevant results of a topology proposal

        Returns
        -------
        new_positions : [n, 3] ndarray
            The new positions of the system
        logp_proposal : float
            The log probability of the forward-only proposal
        """
        beta = top_proposal.beta
        logp_proposal = 0.0
        structure = parmed.openmm.load_topology(top_proposal.new_topology, top_proposal.new_system)
        new_atoms = [structure.atoms[idx] for idx in top_proposal.unique_new_atoms]
        atoms_with_positions = [structure.atoms[atom_idx] for atom_idx in range(top_proposal.n_atoms_new) if atom_idx not in top_proposal.unique_new_atoms]
        new_positions = units.Quantity(np.zeros([top_proposal.n_atoms_new, 3]), unit=units.nanometers)
        #copy positions
        for atom in atoms_with_positions:
            old_index = top_proposal.new_to_old_atom_map[atom.idx]
            new_positions[atom.idx] = top_proposal.old_positions[old_index]

        #maintain a running list of the atoms still needing positions
        while(len(new_atoms)>0):
            atoms_for_proposal = self._atoms_eligible_for_proposal(new_atoms, structure, atoms_with_positions)
            for atom in atoms_for_proposal:
                torsion, logp_choice = self._choose_torsion(atoms_with_positions, atom)

                if torsion.atom1 == atom:
                    bond_atom = torsion.atom2
github openforcefield / smarty / smarty / forcefield_utils.py View on Github external
Parameters
    ----------
    topology : OpenMM Topology
        Topology of the system to be saved, perhaps as loaded from a PDB file or similar.
    system : OpenMM System
        Parameterized System to be saved, containing components represented by Topology
    positions : unit.Quantity position array
        Position array containing positions of atoms in topology/system
    prmtop : filename
        AMBER parameter file name to write
    crd : filename
        AMBER coordinate file name (ASCII crd format) to write

    """

    structure = parmed.openmm.topsystem.load_topology( topology, system, positions )
    structure.save( prmtop, overwrite = True, format="amber" )
    structure.save( crd, format='rst7', overwrite = True)
github choderalab / perses / perses / rjmc / geometry.py View on Github external
top_proposal : TopologyProposal object
            Object containing the relevant results of a topology proposal
        new_coordinates : [n, 3] np.ndarray
            The coordinates of the system after the proposal
        old_coordiantes : [n, 3] np.ndarray
            The coordinates of the system before the proposal

        Returns
        -------
        logp : float
            The log probability of the proposal for the given transformation
        """
        beta = top_proposal.beta
        logp = 0.0
        top_proposal = topology_proposal.SmallMoleculeTopologyProposal()
        structure = parmed.openmm.load_topology(top_proposal.old_topology, top_proposal.old_system)
        atoms_with_positions = [structure.atoms[atom_idx] for atom_idx in range(top_proposal.n_atoms_old) if atom_idx not in top_proposal.unique_old_atoms]
        new_atoms = [structure.atoms[idx] for idx in top_proposal.unique_old_atoms]
        #we'll need to copy the current positions of the core to the old system
        #In the case of C-A --> C/-A -> C/-B ---> C-B these are the same
        reverse_proposal_coordinates = units.Quantity(np.zeros([top_proposal.n_atoms_new, 3]), unit=units.nanometers)
        for atom in atoms_with_positions:
            new_index = top_proposal.old_to_new_atom_map[atom.idx]
            reverse_proposal_coordinates[atom.idx] = new_coordinates[new_index]

        #maintain a running list of the atoms still needing logp
        while(len(new_atoms)>0):
            atoms_for_proposal = self._atoms_eligible_for_proposal(new_atoms, structure, atoms_with_positions)
            for atom in atoms_for_proposal:
                torsion, logp_choice = self._choose_torsion(atoms_with_positions, atom)
                if torsion.atom1 == atom:
                    bond_atom = torsion.atom2
github MobleyLab / blues / blues / storage.py View on Github external
if outfname:
        fh = logging.FileHandler(outfname + '.log')
        fh.setFormatter(fmt)
        logger.addHandler(fh)

    logger.addHandler(logging.NullHandler())
    logger.setLevel(level)

    return logger

######################
#     REPORTERS      #
######################


class NetCDF4Storage(parmed.openmm.reporters.NetCDFReporter):
    """
    Class to read or write NetCDF trajectory files
    Inherited from `parmed.openmm.reporters.NetCDFReporter`

    Parameters
    ----------
    file : str
        Name of the file to write the trajectory to
    reportInterval : int
        How frequently to write a frame to the trajectory
    frame_indices : list, frame numbers for writing the trajectory
        If this reporter is used for the NCMC simulation,
        0.5 will report at the moveStep and -1 will record at the last frame.
    crds : bool=True
        Should we write coordinates to this trajectory? (Default True)
    vels : bool=False
github openforcefield / smarty / smarty / forcefield_utils.py View on Github external
Parameters
    ----------
    topology : OpenMM Topology
        Topology of the system to be saved, perhaps as loaded from a PDB file or similar.
    system : OpenMM System
        Parameterized System to be saved, containing components represented by Topology
    positions : unit.Quantity position array
        Position array containing positions of atoms in topology/system
    top : filename
        GROMACS topology file name to write
    gro : filename
        GROMACS coordinate file name (.gro format) to write

    """

    structure = parmed.openmm.topsystem.load_topology( topology, system, positions )
    structure.save( top, overwrite = True, format="gromacs")
    structure.save( gro, overwrite = True, format="gro")