def createSystem(self, nonbondedMethod=ff.NoCutoff, nonbondedCutoff=1.0*unit.nanometer, constraints=None, rigidWater=True, implicitSolvent=None, soluteDielectric=1.0, solventDielectric=78.5, removeCMMotion=True, ewaldErrorTolerance=0.0005): """Construct an OpenMM System representing the topology described by this prmtop file. Parameters: - nonbondedMethod (object=NoCutoff) The method to use for nonbonded interactions. Allowed values are NoCutoff, CutoffNonPeriodic, CutoffPeriodic, Ewald, or PME. - nonbondedCutoff (distance=1*nanometer) The cutoff distance to use for nonbonded interactions - constraints (object=None) Specifies which bonds angles should be implemented with constraints. Allowed values are None, HBonds, AllBonds, or HAngles. - rigidWater (boolean=True) If true, water molecules will be fully rigid regardless of the value passed for the constraints argument - implicitSolvent (object=None) If not None, the implicit solvent model to use. Allowed values are HCT, OBC1, OBC2, or GBn. - soluteDielectric (float=1.0) The solute dielectric constant to use in the implicit solvent model. - solventDielectric (float=78.5) The solvent dielectric constant to use in the implicit solvent model. - removeCMMotion (boolean=True) If true, a CMMotionRemover will be added to the System - ewaldErrorTolerance (float=0.0005) The error tolerance to use if nonbondedMethod is Ewald or PME. Returns: the newly created System """ methodMap = {ff.NoCutoff:'NoCutoff', ff.CutoffNonPeriodic:'CutoffNonPeriodic', ff.CutoffPeriodic:'CutoffPeriodic', ff.Ewald:'Ewald', ff.PME:'PME'} if nonbondedMethod not in methodMap: raise ValueError('Illegal value for nonbonded method') if not self._prmtop.getIfBox() and nonbondedMethod in (ff.CutoffPeriodic, ff.Ewald, ff.PME): raise ValueError('Illegal nonbonded method for a non-periodic system') constraintMap = {None:None, ff.HBonds:'h-bonds', ff.AllBonds:'all-bonds', ff.HAngles:'h-angles'} if constraints is None: constraintString = None elif constraints in constraintMap: constraintString = constraintMap[constraints] else: raise ValueError('Illegal value for constraints') if implicitSolvent is None: implicitString = None elif implicitSolvent == HCT: implicitString = 'HCT' elif implicitSolvent == OBC1: implicitString = 'OBC1' elif implicitSolvent == OBC2: implicitString = 'OBC2' elif implicitSolvent == GBn: implicitString = 'GBn' else: raise ValueError('Illegal value for implicit solvent model') sys = amber_file_parser.readAmberSystem(prmtop_loader=self._prmtop, shake=constraintString, nonbondedCutoff=nonbondedCutoff, nonbondedMethod=methodMap[nonbondedMethod], flexibleConstraints=False, gbmodel=implicitString, soluteDielectric=soluteDielectric, solventDielectric=solventDielectric, rigidWater=rigidWater) for force in sys.getForces(): if isinstance(force, mm.NonbondedForce): force.setEwaldErrorTolerance(ewaldErrorTolerance) if removeCMMotion: sys.addForce(mm.CMMotionRemover()) return sys
def createSystem(self, nonbondedMethod=ff.NoCutoff, nonbondedCutoff=1.0 * unit.nanometer, constraints=None, rigidWater=True, implicitSolvent=None, implicitSolventSaltConc=0.0 * (unit.moles / unit.liter), implicitSolventKappa=None, temperature=298.15 * unit.kelvin, soluteDielectric=1.0, solventDielectric=78.5, removeCMMotion=True, hydrogenMass=None, ewaldErrorTolerance=0.0005): """Construct an OpenMM System representing the topology described by this prmtop file. Parameters: - nonbondedMethod (object=NoCutoff) The method to use for nonbonded interactions. Allowed values are NoCutoff, CutoffNonPeriodic, CutoffPeriodic, Ewald, or PME. - nonbondedCutoff (distance=1*nanometer) The cutoff distance to use for nonbonded interactions - constraints (object=None) Specifies which bonds angles should be implemented with constraints. Allowed values are None, HBonds, AllBonds, or HAngles. - rigidWater (boolean=True) If true, water molecules will be fully rigid regardless of the value passed for the constraints argument - implicitSolvent (object=None) If not None, the implicit solvent model to use. Allowed values are HCT, OBC1, OBC2, GBn, or GBn2. - implicitSolventSaltConc (float=0.0*unit.moles/unit.liter) The salt concentration for GB calculations (modelled as a debye screening parameter). It is converted to the debye length (kappa) using the provided temperature and solventDielectric - temperature (float=300*kelvin) Temperature of the system. Only used to compute the Debye length from implicitSolventSoltConc - implicitSolventKappa (float units of 1/length) If this value is set, implicitSolventSaltConc will be ignored. - soluteDielectric (float=1.0) The solute dielectric constant to use in the implicit solvent model. - solventDielectric (float=78.5) The solvent dielectric constant to use in the implicit solvent model. - removeCMMotion (boolean=True) If true, a CMMotionRemover will be added to the System - hydrogenMass (mass=None) The mass to use for hydrogen atoms bound to heavy atoms. Any mass added to a hydrogen is subtracted from the heavy atom to keep their total mass the same. - ewaldErrorTolerance (float=0.0005) The error tolerance to use if nonbondedMethod is Ewald or PME. Returns: the newly created System """ methodMap = { ff.NoCutoff: 'NoCutoff', ff.CutoffNonPeriodic: 'CutoffNonPeriodic', ff.CutoffPeriodic: 'CutoffPeriodic', ff.Ewald: 'Ewald', ff.PME: 'PME' } if nonbondedMethod not in methodMap: raise ValueError('Illegal value for nonbonded method') if not self._prmtop.getIfBox() and nonbondedMethod in ( ff.CutoffPeriodic, ff.Ewald, ff.PME): raise ValueError( 'Illegal nonbonded method for a non-periodic system') constraintMap = { None: None, ff.HBonds: 'h-bonds', ff.AllBonds: 'all-bonds', ff.HAngles: 'h-angles' } if constraints is None: constraintString = None elif constraints in constraintMap: constraintString = constraintMap[constraints] else: raise ValueError('Illegal value for constraints') if implicitSolvent is None: implicitString = None elif implicitSolvent is HCT: implicitString = 'HCT' elif implicitSolvent is OBC1: implicitString = 'OBC1' elif implicitSolvent is OBC2: implicitString = 'OBC2' elif implicitSolvent is GBn: implicitString = 'GBn' elif implicitSolvent is GBn2: implicitString = 'GBn2' else: raise ValueError('Illegal value for implicit solvent model') # If implicitSolventKappa is None, compute it from the salt concentration if implicitSolvent is not None and implicitSolventKappa is None: if unit.is_quantity(implicitSolventSaltConc): implicitSolventSaltConc = implicitSolventSaltConc.value_in_unit( unit.moles / unit.liter) if unit.is_quantity(temperature): temperature = temperature.value_in_unit(unit.kelvin) # The constant is 1 / sqrt( epsilon_0 * kB / (2 * NA * q^2 * 1000) ) # where NA is avogadro's number, epsilon_0 is the permittivity of # free space, q is the elementary charge (this number matches # Amber's kappa conversion factor) implicitSolventKappa = 50.33355 * sqrt( implicitSolventSaltConc / solventDielectric / temperature) # Multiply by 0.73 to account for ion exclusions, and multiply by 10 # to convert to 1/nm from 1/angstroms implicitSolventKappa *= 7.3 elif implicitSolvent is None: implicitSolventKappa = 0.0 sys = amber_file_parser.readAmberSystem( prmtop_loader=self._prmtop, shake=constraintString, nonbondedCutoff=nonbondedCutoff, nonbondedMethod=methodMap[nonbondedMethod], flexibleConstraints=False, gbmodel=implicitString, soluteDielectric=soluteDielectric, solventDielectric=solventDielectric, implicitSolventKappa=implicitSolventKappa, rigidWater=rigidWater, elements=self.elements) if hydrogenMass is not None: for atom1, atom2 in self.topology.bonds(): if atom1.element == elem.hydrogen: (atom1, atom2) = (atom2, atom1) if atom2.element == elem.hydrogen and atom1.element not in ( elem.hydrogen, None): transferMass = hydrogenMass - sys.getParticleMass( atom2.index) sys.setParticleMass(atom2.index, hydrogenMass) sys.setParticleMass( atom1.index, sys.getParticleMass(atom1.index) - transferMass) for force in sys.getForces(): if isinstance(force, mm.NonbondedForce): force.setEwaldErrorTolerance(ewaldErrorTolerance) if removeCMMotion: sys.addForce(mm.CMMotionRemover()) return sys
def createSystem(self, nonbondedMethod=ff.NoCutoff, nonbondedCutoff=1.0*unit.nanometer, constraints=None, rigidWater=True, implicitSolvent=None, implicitSolventSaltConc=0.0*(unit.moles/unit.liter), implicitSolventKappa=None, temperature=298.15*unit.kelvin, soluteDielectric=1.0, solventDielectric=78.5, removeCMMotion=True, hydrogenMass=None, ewaldErrorTolerance=0.0005): """Construct an OpenMM System representing the topology described by this prmtop file. Parameters: - nonbondedMethod (object=NoCutoff) The method to use for nonbonded interactions. Allowed values are NoCutoff, CutoffNonPeriodic, CutoffPeriodic, Ewald, or PME. - nonbondedCutoff (distance=1*nanometer) The cutoff distance to use for nonbonded interactions - constraints (object=None) Specifies which bonds angles should be implemented with constraints. Allowed values are None, HBonds, AllBonds, or HAngles. - rigidWater (boolean=True) If true, water molecules will be fully rigid regardless of the value passed for the constraints argument - implicitSolvent (object=None) If not None, the implicit solvent model to use. Allowed values are HCT, OBC1, OBC2, GBn, or GBn2. - implicitSolventSaltConc (float=0.0*unit.moles/unit.liter) The salt concentration for GB calculations (modelled as a debye screening parameter). It is converted to the debye length (kappa) using the provided temperature and solventDielectric - temperature (float=300*kelvin) Temperature of the system. Only used to compute the Debye length from implicitSolventSoltConc - implicitSolventKappa (float units of 1/length) If this value is set, implicitSolventSaltConc will be ignored. - soluteDielectric (float=1.0) The solute dielectric constant to use in the implicit solvent model. - solventDielectric (float=78.5) The solvent dielectric constant to use in the implicit solvent model. - removeCMMotion (boolean=True) If true, a CMMotionRemover will be added to the System - hydrogenMass (mass=None) The mass to use for hydrogen atoms bound to heavy atoms. Any mass added to a hydrogen is subtracted from the heavy atom to keep their total mass the same. - ewaldErrorTolerance (float=0.0005) The error tolerance to use if nonbondedMethod is Ewald or PME. Returns: the newly created System """ if self._prmtop.chamber: raise ValueError("CHAMBER-style topology file detected. CHAMBER " "topologies are not supported -- use the native " "CHARMM files directly.") methodMap = {ff.NoCutoff:'NoCutoff', ff.CutoffNonPeriodic:'CutoffNonPeriodic', ff.CutoffPeriodic:'CutoffPeriodic', ff.Ewald:'Ewald', ff.PME:'PME'} if nonbondedMethod not in methodMap: raise ValueError('Illegal value for nonbonded method') if not self._prmtop.getIfBox() and nonbondedMethod in (ff.CutoffPeriodic, ff.Ewald, ff.PME): raise ValueError('Illegal nonbonded method for a non-periodic system') constraintMap = {None:None, ff.HBonds:'h-bonds', ff.AllBonds:'all-bonds', ff.HAngles:'h-angles'} if constraints is None: constraintString = None elif constraints in constraintMap: constraintString = constraintMap[constraints] else: raise ValueError('Illegal value for constraints') if implicitSolvent is None: implicitString = None elif implicitSolvent is HCT: implicitString = 'HCT' elif implicitSolvent is OBC1: implicitString = 'OBC1' elif implicitSolvent is OBC2: implicitString = 'OBC2' elif implicitSolvent is GBn: implicitString = 'GBn' elif implicitSolvent is GBn2: implicitString = 'GBn2' else: raise ValueError('Illegal value for implicit solvent model') # If implicitSolventKappa is None, compute it from the salt concentration if implicitSolvent is not None and implicitSolventKappa is None: if unit.is_quantity(implicitSolventSaltConc): implicitSolventSaltConc = implicitSolventSaltConc.value_in_unit(unit.moles/unit.liter) if unit.is_quantity(temperature): temperature = temperature.value_in_unit(unit.kelvin) # The constant is 1 / sqrt( epsilon_0 * kB / (2 * NA * q^2 * 1000) ) # where NA is avogadro's number, epsilon_0 is the permittivity of # free space, q is the elementary charge (this number matches # Amber's kappa conversion factor) implicitSolventKappa = 50.33355 * sqrt(implicitSolventSaltConc / solventDielectric / temperature) # Multiply by 0.73 to account for ion exclusions, and multiply by 10 # to convert to 1/nm from 1/angstroms implicitSolventKappa *= 7.3 elif implicitSolvent is None: implicitSolventKappa = 0.0 sys = amber_file_parser.readAmberSystem(self.topology, prmtop_loader=self._prmtop, shake=constraintString, nonbondedCutoff=nonbondedCutoff, nonbondedMethod=methodMap[nonbondedMethod], flexibleConstraints=False, gbmodel=implicitString, soluteDielectric=soluteDielectric, solventDielectric=solventDielectric, implicitSolventKappa=implicitSolventKappa, rigidWater=rigidWater, elements=self.elements) if hydrogenMass is not None: for atom1, atom2 in self.topology.bonds(): if atom1.element == elem.hydrogen: (atom1, atom2) = (atom2, atom1) if atom2.element == elem.hydrogen and atom1.element not in (elem.hydrogen, None): transferMass = hydrogenMass-sys.getParticleMass(atom2.index) sys.setParticleMass(atom2.index, hydrogenMass) sys.setParticleMass(atom1.index, sys.getParticleMass(atom1.index)-transferMass) for force in sys.getForces(): if isinstance(force, mm.NonbondedForce): force.setEwaldErrorTolerance(ewaldErrorTolerance) if removeCMMotion: sys.addForce(mm.CMMotionRemover()) return sys
def createSystem( self, nonbondedMethod=ff.NoCutoff, nonbondedCutoff=1.0 * u.nanometer, constraints=None, rigidWater=True, implicitSolvent=None, implicitSolventSaltConc=0.0 * (u.moles / u.liter), implicitSolventKappa=None, temperature=298.15 * u.kelvin, soluteDielectric=1.0, solventDielectric=78.5, removeCMMotion=True, hydrogenMass=None, ewaldErrorTolerance=0.0005, switchDistance=0.0 * u.nanometer, ): """Construct an OpenMM System representing the topology described by this prmtop file. Parameters ---------- nonbondedMethod : object=NoCutoff The method to use for nonbonded interactions. Allowed values are NoCutoff, CutoffNonPeriodic, CutoffPeriodic, Ewald, or PME. nonbondedCutoff : distance=1*nanometer The cutoff distance to use for nonbonded interactions constraints : object=None Specifies which bonds angles should be implemented with constraints. Allowed values are None, HBonds, AllBonds, or HAngles. rigidWater : boolean=True If true, water molecules will be fully rigid regardless of the value passed for the constraints argument implicitSolvent : object=None If not None, the implicit solvent model to use. Allowed values are HCT, OBC1, OBC2, GBn, or GBn2. implicitSolventSaltConc : float=0.0*unit.moles/unit.liter The salt concentration for GB calculations (modelled as a debye screening parameter). It is converted to the debye length (kappa) using the provided temperature and solventDielectric temperature : float=300*kelvin Temperature of the system. Only used to compute the Debye length from implicitSolventSoltConc implicitSolventKappa : float units of 1/length If this value is set, implicitSolventSaltConc will be ignored. soluteDielectric : float=1.0 The solute dielectric constant to use in the implicit solvent model. solventDielectric : float=78.5 The solvent dielectric constant to use in the implicit solvent model. removeCMMotion : boolean=True If true, a CMMotionRemover will be added to the System hydrogenMass : mass=None The mass to use for hydrogen atoms bound to heavy atoms. Any mass added to a hydrogen is subtracted from the heavy atom to keep their total mass the same. ewaldErrorTolerance : float=0.0005 The error tolerance to use if nonbondedMethod is Ewald or PME. switchDistance : float=0*nanometers The distance at which the potential energy switching function is turned on for Lennard-Jones interactions. If the switchDistance is 0 or evaluates to boolean False, no switching function will be used. Values greater than nonbondedCutoff or less than 0 raise ValueError Returns ------- System the newly created System """ if self._prmtop.chamber: raise ValueError( "CHAMBER-style topology file detected. CHAMBER " "topologies are not supported -- use the native " "CHARMM files directly." ) methodMap = { ff.NoCutoff: "NoCutoff", ff.CutoffNonPeriodic: "CutoffNonPeriodic", ff.CutoffPeriodic: "CutoffPeriodic", ff.Ewald: "Ewald", ff.PME: "PME", } if nonbondedMethod not in methodMap: raise ValueError("Illegal value for nonbonded method") if not self._prmtop.getIfBox() and nonbondedMethod in (ff.CutoffPeriodic, ff.Ewald, ff.PME): raise ValueError("Illegal nonbonded method for a non-periodic system") constraintMap = {None: None, ff.HBonds: "h-bonds", ff.AllBonds: "all-bonds", ff.HAngles: "h-angles"} if constraints is None: constraintString = None elif constraints in constraintMap: constraintString = constraintMap[constraints] else: raise ValueError("Illegal value for constraints") if implicitSolvent is None: implicitString = None elif implicitSolvent is HCT: implicitString = "HCT" elif implicitSolvent is OBC1: implicitString = "OBC1" elif implicitSolvent is OBC2: implicitString = "OBC2" elif implicitSolvent is GBn: implicitString = "GBn" elif implicitSolvent is GBn2: implicitString = "GBn2" else: raise ValueError("Illegal value for implicit solvent model") # If implicitSolventKappa is None, compute it from the salt concentration if implicitSolvent is not None and implicitSolventKappa is None: if u.is_quantity(implicitSolventSaltConc): implicitSolventSaltConc = implicitSolventSaltConc.value_in_unit(u.moles / u.liter) if u.is_quantity(temperature): temperature = temperature.value_in_unit(u.kelvin) # The constant is 1 / sqrt( epsilon_0 * kB / (2 * NA * q^2 * 1000) ) # where NA is avogadro's number, epsilon_0 is the permittivity of # free space, q is the elementary charge (this number matches # Amber's kappa conversion factor) implicitSolventKappa = 50.33355 * sqrt(implicitSolventSaltConc / solventDielectric / temperature) # Multiply by 0.73 to account for ion exclusions, and multiply by 10 # to convert to 1/nm from 1/angstroms implicitSolventKappa *= 7.3 elif implicitSolvent is None: implicitSolventKappa = 0.0 sys = amber_file_parser.readAmberSystem( self.topology, prmtop_loader=self._prmtop, shake=constraintString, nonbondedCutoff=nonbondedCutoff, nonbondedMethod=methodMap[nonbondedMethod], flexibleConstraints=False, gbmodel=implicitString, soluteDielectric=soluteDielectric, solventDielectric=solventDielectric, implicitSolventKappa=implicitSolventKappa, rigidWater=rigidWater, elements=self.elements, ) if hydrogenMass is not None: for atom1, atom2 in self.topology.bonds(): if atom1.element == elem.hydrogen: (atom1, atom2) = (atom2, atom1) if atom2.element == elem.hydrogen and atom1.element not in (elem.hydrogen, None): transferMass = hydrogenMass - sys.getParticleMass(atom2.index) sys.setParticleMass(atom2.index, hydrogenMass) sys.setParticleMass(atom1.index, sys.getParticleMass(atom1.index) - transferMass) for force in sys.getForces(): if isinstance(force, mm.NonbondedForce): force.setEwaldErrorTolerance(ewaldErrorTolerance) if removeCMMotion: sys.addForce(mm.CMMotionRemover()) if switchDistance and nonbondedMethod is not ff.NoCutoff: # make sure it's legal if _strip_optunit(switchDistance, u.nanometer) >= _strip_optunit(nonbondedCutoff, u.nanometer): raise ValueError("switchDistance is too large compared " "to the cutoff!") if _strip_optunit(switchDistance, u.nanometer) < 0: # Detects negatives for both Quantity and float raise ValueError("switchDistance must be non-negative!") force.setUseSwitchingFunction(True) force.setSwitchingDistance(switchDistance) return sys
def createSystem(self, nonbondedMethod=ff.NoCutoff, nonbondedCutoff=1.0 * u.nanometer, constraints=None, rigidWater=True, implicitSolvent=None, implicitSolventSaltConc=0.0 * (u.moles / u.liter), implicitSolventKappa=None, temperature=298.15 * u.kelvin, soluteDielectric=1.0, solventDielectric=78.5, removeCMMotion=True, hydrogenMass=None, ewaldErrorTolerance=0.0005, switchDistance=0.0 * u.nanometer, gbsaModel='ACE'): """Construct an OpenMM System representing the topology described by this prmtop file. Parameters ---------- nonbondedMethod : object=NoCutoff The method to use for nonbonded interactions. Allowed values are NoCutoff, CutoffNonPeriodic, CutoffPeriodic, Ewald, PME, or LJPME. nonbondedCutoff : distance=1*nanometer The cutoff distance to use for nonbonded interactions constraints : object=None Specifies which bonds angles should be implemented with constraints. Allowed values are None, HBonds, AllBonds, or HAngles. rigidWater : boolean=True If true, water molecules will be fully rigid regardless of the value passed for the constraints argument implicitSolvent : object=None If not None, the implicit solvent model to use. Allowed values are HCT, OBC1, OBC2, GBn, or GBn2. implicitSolventSaltConc : float=0.0*unit.moles/unit.liter The salt concentration for GB calculations (modelled as a debye screening parameter). It is converted to the debye length (kappa) using the provided temperature and solventDielectric temperature : float=300*kelvin Temperature of the system. Only used to compute the Debye length from implicitSolventSoltConc implicitSolventKappa : float units of 1/length If this value is set, implicitSolventSaltConc will be ignored. soluteDielectric : float=1.0 The solute dielectric constant to use in the implicit solvent model. solventDielectric : float=78.5 The solvent dielectric constant to use in the implicit solvent model. removeCMMotion : boolean=True If true, a CMMotionRemover will be added to the System hydrogenMass : mass=None The mass to use for hydrogen atoms bound to heavy atoms. Any mass added to a hydrogen is subtracted from the heavy atom to keep their total mass the same. If rigidWater is used to make water molecules rigid, then water hydrogens are not altered. ewaldErrorTolerance : float=0.0005 The error tolerance to use if nonbondedMethod is Ewald, PME, or LJPME. switchDistance : float=0*nanometers The distance at which the potential energy switching function is turned on for Lennard-Jones interactions. If the switchDistance is 0 or evaluates to boolean False, no switching function will be used. Values greater than nonbondedCutoff or less than 0 raise ValueError gbsaModel : str='ACE' The SA model used to model the nonpolar solvation component of GB implicit solvent models. If GB is active, this must be 'ACE' or None (the latter indicates no SA model will be used). Other values will result in a ValueError Returns ------- System the newly created System """ if self._prmtop.chamber: raise ValueError("CHAMBER-style topology file detected. CHAMBER " "topologies are not supported -- use the native " "CHARMM files directly.") methodMap = { ff.NoCutoff: 'NoCutoff', ff.CutoffNonPeriodic: 'CutoffNonPeriodic', ff.CutoffPeriodic: 'CutoffPeriodic', ff.Ewald: 'Ewald', ff.PME: 'PME', ff.LJPME: 'LJPME' } if nonbondedMethod not in methodMap: raise ValueError('Illegal value for nonbonded method') if not self._prmtop.getIfBox() and nonbondedMethod in ( ff.CutoffPeriodic, ff.Ewald, ff.PME, ff.LJPME): raise ValueError( 'Illegal nonbonded method for a non-periodic system') constraintMap = { None: None, ff.HBonds: 'h-bonds', ff.AllBonds: 'all-bonds', ff.HAngles: 'h-angles' } if constraints is None: constraintString = None elif constraints in constraintMap: constraintString = constraintMap[constraints] else: raise ValueError('Illegal value for constraints') if implicitSolvent is None: implicitString = None elif implicitSolvent is HCT: implicitString = 'HCT' elif implicitSolvent is OBC1: implicitString = 'OBC1' elif implicitSolvent is OBC2: implicitString = 'OBC2' elif implicitSolvent is GBn: implicitString = 'GBn' elif implicitSolvent is GBn2: implicitString = 'GBn2' else: raise ValueError('Illegal value for implicit solvent model') # If implicitSolventKappa is None, compute it from the salt concentration if implicitSolvent is not None and implicitSolventKappa is None: if u.is_quantity(implicitSolventSaltConc): implicitSolventSaltConc = implicitSolventSaltConc.value_in_unit( u.moles / u.liter) if u.is_quantity(temperature): temperature = temperature.value_in_unit(u.kelvin) # The constant is 1 / sqrt( epsilon_0 * kB / (2 * NA * q^2 * 1000) ) # where NA is avogadro's number, epsilon_0 is the permittivity of # free space, q is the elementary charge (this number matches # Amber's kappa conversion factor) implicitSolventKappa = 50.33355 * sqrt( implicitSolventSaltConc / solventDielectric / temperature) # Multiply by 0.73 to account for ion exclusions, and multiply by 10 # to convert to 1/nm from 1/angstroms implicitSolventKappa *= 7.3 elif implicitSolvent is None: implicitSolventKappa = 0.0 sys = amber_file_parser.readAmberSystem( self.topology, prmtop_loader=self._prmtop, shake=constraintString, nonbondedCutoff=nonbondedCutoff, nonbondedMethod=methodMap[nonbondedMethod], flexibleConstraints=False, gbmodel=implicitString, soluteDielectric=soluteDielectric, solventDielectric=solventDielectric, implicitSolventKappa=implicitSolventKappa, rigidWater=rigidWater, elements=self.elements, gbsaModel=gbsaModel) if hydrogenMass is not None: for atom1, atom2 in self.topology.bonds(): if atom1.element == elem.hydrogen: (atom1, atom2) = (atom2, atom1) if rigidWater and atom2.residue.name == 'HOH': continue if atom2.element == elem.hydrogen and atom1.element not in ( elem.hydrogen, None): transferMass = hydrogenMass - sys.getParticleMass( atom2.index) sys.setParticleMass(atom2.index, hydrogenMass) sys.setParticleMass( atom1.index, sys.getParticleMass(atom1.index) - transferMass) for force in sys.getForces(): if isinstance(force, mm.NonbondedForce): force.setEwaldErrorTolerance(ewaldErrorTolerance) if removeCMMotion: sys.addForce(mm.CMMotionRemover()) if switchDistance and nonbondedMethod is not ff.NoCutoff: # make sure it's legal if (_strip_optunit(switchDistance, u.nanometer) >= _strip_optunit( nonbondedCutoff, u.nanometer)): raise ValueError('switchDistance is too large compared ' 'to the cutoff!') if _strip_optunit(switchDistance, u.nanometer) < 0: # Detects negatives for both Quantity and float raise ValueError('switchDistance must be non-negative!') force.setUseSwitchingFunction(True) force.setSwitchingDistance(switchDistance) return sys
def createSystem(self, nonbondedMethod=ff.NoCutoff, nonbondedCutoff=1.0 * unit.nanometer, constraints=None, rigidWater=True, implicitSolvent=None, soluteDielectric=1.0, solventDielectric=78.5, removeCMMotion=True, hydrogenMass=None, ewaldErrorTolerance=0.0005): """Construct an OpenMM System representing the topology described by this prmtop file. Parameters: - nonbondedMethod (object=NoCutoff) The method to use for nonbonded interactions. Allowed values are NoCutoff, CutoffNonPeriodic, CutoffPeriodic, Ewald, or PME. - nonbondedCutoff (distance=1*nanometer) The cutoff distance to use for nonbonded interactions - constraints (object=None) Specifies which bonds angles should be implemented with constraints. Allowed values are None, HBonds, AllBonds, or HAngles. - rigidWater (boolean=True) If true, water molecules will be fully rigid regardless of the value passed for the constraints argument - implicitSolvent (object=None) If not None, the implicit solvent model to use. Allowed values are HCT, OBC1, OBC2, GBn, or GBn2. - soluteDielectric (float=1.0) The solute dielectric constant to use in the implicit solvent model. - solventDielectric (float=78.5) The solvent dielectric constant to use in the implicit solvent model. - removeCMMotion (boolean=True) If true, a CMMotionRemover will be added to the System - hydrogenMass (mass=None) The mass to use for hydrogen atoms bound to heavy atoms. Any mass added to a hydrogen is subtracted from the heavy atom to keep their total mass the same. - ewaldErrorTolerance (float=0.0005) The error tolerance to use if nonbondedMethod is Ewald or PME. Returns: the newly created System """ methodMap = { ff.NoCutoff: 'NoCutoff', ff.CutoffNonPeriodic: 'CutoffNonPeriodic', ff.CutoffPeriodic: 'CutoffPeriodic', ff.Ewald: 'Ewald', ff.PME: 'PME' } if nonbondedMethod not in methodMap: raise ValueError('Illegal value for nonbonded method') if not self._prmtop.getIfBox() and nonbondedMethod in ( ff.CutoffPeriodic, ff.Ewald, ff.PME): raise ValueError( 'Illegal nonbonded method for a non-periodic system') constraintMap = { None: None, ff.HBonds: 'h-bonds', ff.AllBonds: 'all-bonds', ff.HAngles: 'h-angles' } if constraints is None: constraintString = None elif constraints in constraintMap: constraintString = constraintMap[constraints] else: raise ValueError('Illegal value for constraints') if implicitSolvent is None: implicitString = None elif implicitSolvent is HCT: implicitString = 'HCT' elif implicitSolvent is OBC1: implicitString = 'OBC1' elif implicitSolvent is OBC2: implicitString = 'OBC2' elif implicitSolvent is GBn: implicitString = 'GBn' elif implicitSolvent is GBn2: implicitString = 'GBn2' else: raise ValueError('Illegal value for implicit solvent model') sys = amber_file_parser.readAmberSystem( prmtop_loader=self._prmtop, shake=constraintString, nonbondedCutoff=nonbondedCutoff, nonbondedMethod=methodMap[nonbondedMethod], flexibleConstraints=False, gbmodel=implicitString, soluteDielectric=soluteDielectric, solventDielectric=solventDielectric, rigidWater=rigidWater, elements=self.elements) if hydrogenMass is not None: for atom1, atom2 in self.topology.bonds(): if atom1.element == elem.hydrogen: (atom1, atom2) = (atom2, atom1) if atom2.element == elem.hydrogen and atom1.element not in ( elem.hydrogen, None): transferMass = hydrogenMass - sys.getParticleMass( atom2.index) sys.setParticleMass(atom2.index, hydrogenMass) sys.setParticleMass( atom1.index, sys.getParticleMass(atom1.index) - transferMass) for force in sys.getForces(): if isinstance(force, mm.NonbondedForce): force.setEwaldErrorTolerance(ewaldErrorTolerance) if removeCMMotion: sys.addForce(mm.CMMotionRemover()) return sys
def createSystem(self, nonbondedMethod=ff.NoCutoff, nonbondedCutoff=1.0*unit.nanometer, constraints=None, rigidWater=True, implicitSolvent=None, implicitSolventKappa=0.0*(1/unit.nanometer), soluteDielectric=1.0, solventDielectric=78.5, removeCMMotion=True, hydrogenMass=None, ewaldErrorTolerance=0.0005): """Construct an OpenMM System representing the topology described by this prmtop file. Parameters: - nonbondedMethod (object=NoCutoff) The method to use for nonbonded interactions. Allowed values are NoCutoff, CutoffNonPeriodic, CutoffPeriodic, Ewald, or PME. - nonbondedCutoff (distance=1*nanometer) The cutoff distance to use for nonbonded interactions - constraints (object=None) Specifies which bonds angles should be implemented with constraints. Allowed values are None, HBonds, AllBonds, or HAngles. - rigidWater (boolean=True) If true, water molecules will be fully rigid regardless of the value passed for the constraints argument - implicitSolvent (object=None) If not None, the implicit solvent model to use. Allowed values are HCT, OBC1, OBC2, GBn, or GBn2. - implicitSolventKappa (float=0.0*1/unit.nanometer) The Debye-screening parameter corresponding to ionic strength used for implicit solvent - soluteDielectric (float=1.0) The solute dielectric constant to use in the implicit solvent model. - solventDielectric (float=78.5) The solvent dielectric constant to use in the implicit solvent model. - removeCMMotion (boolean=True) If true, a CMMotionRemover will be added to the System - hydrogenMass (mass=None) The mass to use for hydrogen atoms bound to heavy atoms. Any mass added to a hydrogen is subtracted from the heavy atom to keep their total mass the same. - ewaldErrorTolerance (float=0.0005) The error tolerance to use if nonbondedMethod is Ewald or PME. Returns: the newly created System """ methodMap = {ff.NoCutoff:'NoCutoff', ff.CutoffNonPeriodic:'CutoffNonPeriodic', ff.CutoffPeriodic:'CutoffPeriodic', ff.Ewald:'Ewald', ff.PME:'PME'} if nonbondedMethod not in methodMap: raise ValueError('Illegal value for nonbonded method') if not self._prmtop.getIfBox() and nonbondedMethod in (ff.CutoffPeriodic, ff.Ewald, ff.PME): raise ValueError('Illegal nonbonded method for a non-periodic system') constraintMap = {None:None, ff.HBonds:'h-bonds', ff.AllBonds:'all-bonds', ff.HAngles:'h-angles'} if constraints is None: constraintString = None elif constraints in constraintMap: constraintString = constraintMap[constraints] else: raise ValueError('Illegal value for constraints') if implicitSolvent is None: implicitString = None elif implicitSolvent is HCT: implicitString = 'HCT' elif implicitSolvent is OBC1: implicitString = 'OBC1' elif implicitSolvent is OBC2: implicitString = 'OBC2' elif implicitSolvent is GBn: implicitString = 'GBn' elif implicitSolvent is GBn2: implicitString = 'GBn2' else: raise ValueError('Illegal value for implicit solvent model') sys = amber_file_parser.readAmberSystem(prmtop_loader=self._prmtop, shake=constraintString, nonbondedCutoff=nonbondedCutoff, nonbondedMethod=methodMap[nonbondedMethod], flexibleConstraints=False, gbmodel=implicitString, soluteDielectric=soluteDielectric, solventDielectric=solventDielectric, implicitSolventKappa=implicitSolventKappa, rigidWater=rigidWater, elements=self.elements) if hydrogenMass is not None: for atom1, atom2 in self.topology.bonds(): if atom1.element == elem.hydrogen: (atom1, atom2) = (atom2, atom1) if atom2.element == elem.hydrogen and atom1.element not in (elem.hydrogen, None): transferMass = hydrogenMass-sys.getParticleMass(atom2.index) sys.setParticleMass(atom2.index, hydrogenMass) sys.setParticleMass(atom1.index, sys.getParticleMass(atom1.index)-transferMass) for force in sys.getForces(): if isinstance(force, mm.NonbondedForce): force.setEwaldErrorTolerance(ewaldErrorTolerance) if removeCMMotion: sys.addForce(mm.CMMotionRemover()) return sys