System¶
-
class
OpenMM::System¶ This class represents a molecular system. The definition of a
Systeminvolves four elements:- The set of particles in the system
- The forces acting on them
- Pairs of particles whose separation should be constrained to a fixed value
- For periodic systems, the dimensions of the periodic box
The particles and constraints are defined directly by the
Systemobject, while forces are defined by objects that extend theForceclass. After creating aSystem, calladdParticle()once for each particle,addConstraint()for each constraint, andaddForce()for eachForce.In addition, particles may be designated as “virtual sites”. These are particles whose positions are computed automatically based on the positions of other particles. To define a virtual site, call
setVirtualSite(), passing in aVirtualSiteobject that defines the rules for computing its position.Methods
SystemCreate a new System.~SystemgetNumParticlesGet the number of particles in this System.addParticleAdd a particle to the System.getParticleMassGet the mass (in atomic mass units) of a particle. setParticleMassSet the mass (in atomic mass units) of a particle. setVirtualSiteSet a particle to be a virtual site. isVirtualSiteGet whether a particle is a VirtualSite.getVirtualSiteGet VirtualSiteobject for a particle.getNumConstraintsGet the number of distance constraints in this System.addConstraintAdd a constraint to the System.getConstraintParametersGet the parameters defining a distance constraint. setConstraintParametersSet the parameters defining a distance constraint. removeConstraintRemove a constraint from the System.addForceAdd a Forceto theSystem.getNumForcesGet the number of Forceobjects that have been added to theSystem.getForceGet a const reference to one of the Forces in this System.getForceGet a writable reference to one of the Forces in this System.removeForceRemove a Forcefrom theSystem.getDefaultPeriodicBoxVectorsGet the default values of the vectors defining the axes of the periodic box (measured in nm). setDefaultPeriodicBoxVectorsSet the default values of the vectors defining the axes of the periodic box (measured in nm). usesPeriodicBoundaryConditionsReturns whether or not any forces in this Systemuse periodic boundaries.-
~System()¶
-
int
addParticle(double mass)¶ Add a particle to the
System. If the mass is 0, Integrators will ignore the particle and not modify its position or velocity. This is most often used for virtual sites, but can also be used as a way to prevent a particle from moving.Parameters: - mass – the mass of the particle (in atomic mass units)
Returns: the index of the particle that was added
-
double
getParticleMass(int index) const¶ Get the mass (in atomic mass units) of a particle. If the mass is 0, Integrators will ignore the particle and not modify its position or velocity. This is most often used for virtual sites, but can also be used as a way to prevent a particle from moving.
Parameters: - index – the index of the particle for which to get the mass
-
void
setParticleMass(int index, double mass)¶ Set the mass (in atomic mass units) of a particle. If the mass is 0, Integrators will ignore the particle and not modify its position or velocity. This is most often used for virtual sites, but can also be used as a way to prevent a particle from moving.
Parameters: - index – the index of the particle for which to set the mass
- mass – the mass of the particle
-
void
setVirtualSite(int index, VirtualSite *virtualSite)¶ Set a particle to be a virtual site. The
VirtualSiteobject should have been created on the heap with the “new” operator. TheSystemtakes over ownership of it, and deletes it when theSystemitself is deleted.Parameters: - index – the index of the particle that should be treated as a virtual site
- virtualSite – a pointer to the
VirtualSiteobject describing it
-
bool
isVirtualSite(int index) const¶ Get whether a particle is a
VirtualSite.Parameters: - index – the index of the particle to check
-
const VirtualSite &
getVirtualSite(int index) const¶ Get
VirtualSiteobject for a particle. If the particle is not a virtual site, this throws an exception.Parameters: - index – the index of the particle to get
-
int
addConstraint(int particle1, int particle2, double distance)¶ Add a constraint to the
System. Particles whose mass is 0 cannot participate in constraints.Parameters: - particle1 – the index of the first particle involved in the constraint
- particle2 – the index of the second particle involved in the constraint
- distance – the required distance between the two particles, measured in nm
Returns: the index of the constraint that was added
-
void
getConstraintParameters(int index, int &particle1, int &particle2, double &distance) const¶ Get the parameters defining a distance constraint.
Parameters: - index – the index of the constraint for which to get parameters
- particle1 – [out] the index of the first particle involved in the constraint
- particle2 – [out] the index of the second particle involved in the constraint
- distance – [out] the required distance between the two particles, measured in nm
-
void
setConstraintParameters(int index, int particle1, int particle2, double distance)¶ Set the parameters defining a distance constraint. Particles whose mass is 0 cannot participate in constraints.
Parameters: - index – the index of the constraint for which to set parameters
- particle1 – the index of the first particle involved in the constraint
- particle2 – the index of the second particle involved in the constraint
- distance – the required distance between the two particles, measured in nm
-
void
removeConstraint(int index)¶ Remove a constraint from the
System.Parameters: - index – the index of the constraint to remove
-
int
addForce(Force *force)¶ Add a
Forceto theSystem. TheForceshould have been created on the heap with the “new” operator. TheSystemtakes over ownership of it, and deletes theForcewhen theSystemitself is deleted.Parameters: - force – a pointer to the
Forceobject to be added
Returns: the index within the Systemof theForcethat was added- force – a pointer to the
-
const Force &
getForce(int index) const¶ Get a const reference to one of the Forces in this
System.Parameters: - index – the index of the
Forceto get
- index – the index of the
-
Force &
getForce(int index)¶ Get a writable reference to one of the Forces in this
System.Parameters: - index – the index of the
Forceto get
- index – the index of the
-
void
removeForce(int index)¶ Remove a
Forcefrom theSystem. The memory associated with the removedForceobject is deleted.Parameters: - index – the index of the
Forceto remove
- index – the index of the
-
void
getDefaultPeriodicBoxVectors(Vec3 &a, Vec3 &b, Vec3 &c) const¶ Get the default values of the vectors defining the axes of the periodic box (measured in nm). Any newly created
Contextwill have its box vectors set to these. They will affect anyForceadded to theSystemthat uses periodic boundary conditions.Parameters: - a – [out] the vector defining the first edge of the periodic box
- b – [out] the vector defining the second edge of the periodic box
- c – [out] the vector defining the third edge of the periodic box
-
void
setDefaultPeriodicBoxVectors(const Vec3 &a, const Vec3 &b, const Vec3 &c)¶ Set the default values of the vectors defining the axes of the periodic box (measured in nm). Any newly created
Contextwill have its box vectors set to these. They will affect anyForceadded to theSystemthat uses periodic boundary conditions.Triclinic boxes are supported, but the vectors must satisfy certain requirements. In particular, a must point in the x direction, b must point “mostly” in the y direction, and c must point “mostly” in the z direction. See the documentation for details.
Parameters: - a – the vector defining the first edge of the periodic box
- b – the vector defining the second edge of the periodic box
- c – the vector defining the third edge of the periodic box
-
bool
usesPeriodicBoundaryConditions() const¶ Returns whether or not any forces in this
Systemuse periodic boundaries.If a force in this
Systemdoes not implement usesPeriodicBoundaryConditions aOpenMM::OpenMMExceptionis thrownReturns: true if at least one force uses PBC and false otherwise