An integrator for Langevin dynamics (Python part) — MMTK User Guide 2.7.7 documentation

### Navigation

- index
- modules |
- MMTK User Guide 2.7.7 documentation »

# An integrator for Langevin dynamics (Python part)

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    # This module implements a Langevin integrator.
    #
    # Written by Konrad Hinsen
    #

    from MMTK import Dynamics, Environment, Features, Trajectory, \
                     Units, ParticleProperties
    import MMTK_langevin
    import MMTK_forcefield

    #
    # Langevin integrator
    #
    class LangevinIntegrator(Dynamics.Integrator):

        def __init__(self, universe, **options):
            Dynamics.Integrator.__init__(self, universe, options)
            # Supported features: none for the moment, to keep it simple
            self.features = []

        def __call__(self, **options):
            # Process the keyword arguments
            self.setCallOptions(options)
            # Check if the universe has features not supported by the integrator
            Features.checkFeatures(self, self.universe)
            # Get the universe variables needed by the integrator
            configuration = self.universe.configuration()
            masses = self.universe.masses()
            velocities = self.universe.velocities()
            if velocities is None:
                raise ValueError("no velocities")

            # Get the friction coefficients. First check if a keyword argument
            # 'friction' was given to the integrator. Its value can be a
            # ParticleScalar or a plain number (used for all atoms). If no
            # such argument is given, collect the values of the attribute
            # 'friction' from all atoms (default is zero).
            try:
                friction = self.getOption('friction')
            except KeyError:
                friction = self.universe.getParticleScalar('friction')
            if not ParticleProperties.isParticleProperty(friction):
                var = ParticleProperties.ParticleScalar(self.universe)
                var.array[:] = friction
                friction = var

            # Construct a C evaluator object for the force field, using
            # the specified number of threads or the default value
            nt = self.getOption('threads')
            evaluator = self.universe.energyEvaluator(threads=nt).CEvaluator()

            # Run the C integrator
            MMTK_langevin.integrateLD(self.universe,
                                      configuration.array, velocities.array,
                                      masses.array, friction.array, evaluator,
                                      self.getOption('temperature'),
                                      self.getOption('delta_t'),
                                      self.getOption('steps'),
                                      self.getActions())

### Navigation

- index
- modules |
- MMTK User Guide 2.7.7 documentation »