def __init__(self, resname): super().__init__(_SireMol.ResName(resname))
def _rename_water_molecule(molecule): """Internal function to rename residues/atoms in a water molecule to match the naming conventions used by GROMACS. Parameters ---------- molecule : Sire.Mol.Molecule A Sire Molecule object. Returns ------- molecule : Sire.Mol.Molecule The updated Sire Molecule object. """ # Make the molecule editable. molecule = molecule.edit() # In GROMACS, all water molecules must be given the residue label "SOL". # We extract all of the waters from the system and relabel the # residues as appropriate. # # We need to work out what to do if existing water molecules don't contain # all of the required atoms, e.g. if we have crystal water oxygen sites # from a PDB file, or if the system is to be solvated with a 4- or 5-point # water model (where we need to add virtual sites). # Update the molecule with the new residue name. molecule = molecule.residue(_SireMol.ResIdx(0)) \ .rename(_SireMol.ResName("SOL")) \ .molecule() # Index for the hydrogen atoms. hydrogen_idx = 1 # Gromacs water models use HW1/HW2 for hydrogen atoms at OW for water. for atom in molecule.atoms(): try: # Hydrogen. if atom.property("element") == _SireMol.Element("H"): molecule = molecule.atom(atom.number()) \ .rename(_SireMol.AtomName("HW%d" % hydrogen_idx)) \ .molecule() hydrogen_idx += 1 # Oxygen. elif atom.property("element") == _SireMol.Element("O"): molecule = molecule.atom(atom.number()) \ .rename(_SireMol.AtomName("OW")) \ .molecule() # Otherwise, try to infer the element from the atom name. except: # Strip all digits from the name. name = "".join([x for x in atom.name().value() if not x.isdigit()]) # Remove any whitespace. name = name.replace(" ", "") # Try to infer the element. element = _SireMol.Element.biologicalElement(name) # Hydrogen. if element == _SireMol.Element("H"): molecule = molecule.atom(atom.number()) \ .rename(_SireMol.AtomName("HW%d" % hydrogen_idx)) \ .molecule() hydrogen_idx += 1 # Oxygen. elif element == _SireMol.Element("O"): molecule = molecule.atom(atom.number()) \ .rename(_SireMol.AtomName("OW")) \ .molecule() # Commit and return the updated molecule. return molecule.commit()
def rescaleSystemParams(system, scale, includelist=None, excludelist=None, neutralise=True): """ Rescales charge, Lennard-Jones and dihedral parameters for REST(2). Parameters ---------- system : BioSimSpace.System Input system to be rescaled. scale : float Multiplication factor for the charge, Lennard-Jones and dihedral parameters. 0 < scale < 1. includelist : [str] Molecule names to be included in the rescaling. Default: None. excludelist : [str] Molecule names to be excluded in the rescaling. Default: ["WAT"]. neutralise : bool Whether to rescale a minimum number of Na+ or Cl- ions so that the rescaled part of the system is neutralised. Returns ------- system_new : BioSimSpace.System The rescaled system. """ if excludelist is None and includelist is None: excludelist = ["WAT"] elif excludelist is not None and includelist is not None: raise ValueError("Only one of includelist and excludelist can be set") if neutralise: if excludelist is not None: total_charge = round( sum([ mol.charge().magnitude() for mol in system.getMolecules() if mol._sire_object.name().value() not in excludelist ])) elif includelist is not None: total_charge = round( sum([ mol.charge().magnitude() for mol in system.getMolecules() if mol._sire_object.name().value() in includelist ])) mols_mod = [] for mol in system.getMolecules(): if neutralise and mol._sire_object.name().value().lower( ) == "na" and total_charge < 0: total_charge += 1 elif neutralise and mol._sire_object.name().value().lower( ) == "cl" and total_charge > 0: total_charge -= 1 elif excludelist is not None: if mol._sire_object.name().value() in excludelist: mols_mod += [mol] continue elif includelist is not None: if mol._sire_object.name().value() not in includelist: mols_mod += [mol] continue mol_edit = mol._sire_object.edit() if scale != 1: for prop in [ "dihedral", "dihedral0", "dihedral1", "improper", "improper0", "improper1" ]: try: potentials = mol_edit.property(prop).potentials() prop_new = _SireMM.FourAtomFunctions(mol_edit.info()) for potential in potentials: prop_new.set(potential.atom0(), potential.atom1(), potential.atom2(), potential.atom3(), potential.function() * scale) mol_edit = mol_edit.setProperty(prop, prop_new).molecule() except: continue for atom in mol_edit.atoms(): idx = atom.index() for prop in ["atomtype", "atomtype0", "atomtype1"]: try: atomtype_new = atom.property(prop) + "_" mol_edit = mol_edit.atom(idx).setProperty( prop, atomtype_new).molecule() except: continue if scale != 1: for prop in ["LJ", "LJ0", "LJ1"]: try: LJ = atom.property(prop) LJ = LJ.fromSigmaAndEpsilon(LJ.sigma(), LJ.epsilon() * scale) mol_edit = mol_edit.atom(idx).setProperty( prop, LJ).molecule() except: continue for prop in ["charge", "charge0", "charge1"]: try: charge = atom.property(prop) charge = charge * scale mol_edit = mol_edit.atom(idx).setProperty( prop, charge).molecule() except: continue if mol._sire_object.name().value().lower() in ["na", "cl"]: resname = mol_edit.residue().name() resname_new = _SireMol.ResName(resname.value() + "_") mol_edit = mol_edit.residue(resname).rename(resname_new) mol._sire_object = mol_edit.commit() mols_mod += [mol] system_new = _BSS._SireWrappers._system.System(mols_mod) box = system._sire_object.property("space") system_new._sire_object.setProperty("space", box) return system_new