Coverage for cvpack/distance.py: 100%
10 statements
« prev ^ index » next coverage.py v7.5.1, created at 2024-05-09 16:14 +0000
« prev ^ index » next coverage.py v7.5.1, created at 2024-05-09 16:14 +0000
1"""
2.. class:: Distance
3 :platform: Linux, MacOS, Windows
4 :synopsis: The distance between two atoms
6.. classauthor:: Charlles Abreu <craabreu@gmail.com>
8"""
10import openmm
11from openmm import unit as mmunit
13from .collective_variable import CollectiveVariable
16class Distance(CollectiveVariable, openmm.CustomBondForce):
17 r"""
18 The distance between two atoms:
20 .. math::
22 d({\bf r}) = \| {\bf r}_2 - {\bf r}_1 \|.
24 Parameters
25 ----------
26 atom1
27 The index of the first atom.
28 atom2
29 The index of the second atom.
30 pbc
31 Whether to use periodic boundary conditions.
32 name
33 The name of the collective variable.
35 Example
36 -------
37 >>> import cvpack
38 >>> import openmm
39 >>> system = openmm.System()
40 >>> [system.addParticle(1) for i in range(2)]
41 [0, 1]
42 >>> distance = cvpack.Distance(0, 1)
43 >>> system.addForce(distance)
44 0
45 >>> integrator = openmm.VerletIntegrator(0)
46 >>> platform = openmm.Platform.getPlatformByName('Reference')
47 >>> context = openmm.Context(system, integrator, platform)
48 >>> context.setPositions([openmm.Vec3(0, 0, 0),openmm.Vec3(1, 1, 1)])
49 >>> distance.getValue(context)
50 1.7320... nm
52 """
54 def __init__(
55 self, atom1: int, atom2: int, pbc: bool = False, name: str = "distance"
56 ) -> None:
57 super().__init__("r")
58 self.addBond(atom1, atom2, [])
59 self.setUsesPeriodicBoundaryConditions(pbc)
60 self._registerCV(name, mmunit.nanometers, atom1=atom1, atom2=atom2, pbc=pbc)
63Distance.registerTag("!cvpack.Distance")