/usr/share/pyshared/MMTK/Minimization.py is in python-mmtk 2.7.9-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 | # This module implements energy minimizers.
#
# Written by Konrad Hinsen
#
"""
Energy minimizers
"""
__docformat__ = 'restructuredtext'
from MMTK import Features, Trajectory, Units
from MMTK_minimization import conjugateGradient, steepestDescent
#
# Minimizer base class
#
class Minimizer(Trajectory.TrajectoryGenerator):
def __init__(self, universe, options):
Trajectory.TrajectoryGenerator.__init__(self, universe, options)
default_options = {'steps': 100, 'step_size': 0.02*Units.Ang,
'convergence': 0.01*Units.kJ/(Units.mol*Units.nm),
'background': False, 'threads': None,
'mpi_communicator': None, 'actions': []}
available_data = ['energy', 'configuration', 'gradients']
restart_data = ['configuration', 'energy']
def __call__(self, options):
raise AttributeError
#
# Steepest descent minimizer
#
class SteepestDescentMinimizer(Minimizer):
"""
Steepest-descent minimizer
The minimizer can handle fixed atoms, but no distance constraints.
It is fully thread-safe.
The minimization is started by calling the minimizer object.
All the keyword options (see documnentation of __init__) can be
specified either when creating the minimizer or when calling it.
The following data categories and variables are available for
output:
- category "configuration": configuration and box size (for
periodic universes)
- category "gradients": energy gradients for each atom
- category "energy": potential energy and
norm of the potential energy gradient
"""
def __init__(self, universe, **options):
"""
:param universe: the universe on which the integrator acts
:type universe: :class:`~MMTK.Universe.Universe`
:keyword steps: the number of minimization steps (default is 100)
:type steps: int
:keyword step_size: the initial size of a minimization step
(default is 0.002 nm)
:type step_size: float
:keyword convergence: the root-mean-square gradient length at which
minimization stops (default is 0.01 kJ/mol/nm)
:type convergence: float
:keyword actions: a list of actions to be executed periodically
(default is none)
:type actions: list
:keyword threads: the number of threads to use in energy evaluation
(default set by MMTK_ENERGY_THREADS)
:type threads: int
:keyword background: if True, the integration is executed as a
separate thread (default: False)
:type background: bool
:keyword mpi_communicator: an MPI communicator object, or None,
meaning no parallelization (default: None)
:type mpi_communicator: Scientific.MPI.MPICommunicator
"""
Minimizer.__init__(self, universe, options)
self.features = [Features.FixedParticleFeature,
Features.NoseThermostatFeature,
Features.AndersenBarostatFeature]
def __call__(self, **options):
"""
Run the minimizer. The keyword options are the same as described
under __init__.
"""
self.setCallOptions(options)
Features.checkFeatures(self, self.universe)
configuration = self.universe.configuration()
fixed = self.universe.getAtomBooleanArray('fixed')
nt = self.getOption('threads')
comm = self.getOption('mpi_communicator')
evaluator = self.universe.energyEvaluator(threads=nt,
mpi_communicator=comm)
evaluator = evaluator.CEvaluator()
args = (self.universe,
configuration.array, fixed.array, evaluator,
self.getOption('steps'), self.getOption('step_size'),
self.getOption('convergence'), self.getActions(),
'Steepest descent minimization with ' +
self.optionString(['convergence', 'step_size', 'steps']))
return self.run(steepestDescent, args)
#
# Conjugate gradient minimizer
#
class ConjugateGradientMinimizer(Minimizer):
"""
Conjugate gradient minimizer
The minimizer can handle fixed atoms, but no distance constraints.
It is fully thread-safe.
The minimization is started by calling the minimizer object.
All the keyword options can be specified either when
creating the minimizer or when calling it.
The following data categories and variables are available for
output:
- category "configuration": configuration and box size (for
periodic universes)
- category "gradients": energy gradients for each atom
- category "energy": potential energy and
norm of the potential energy gradient
"""
def __init__(self, universe, **options):
"""
:param universe: the universe on which the integrator acts
:type universe: :class:`~MMTK.Universe.Universe`
:keyword steps: the number of minimization steps (default is 100)
:type steps: int
:keyword step_size: the initial size of a minimization step
(default is 0.002 nm)
:type step_size: float
:keyword convergence: the root-mean-square gradient length at which
minimization stops (default is 0.01 kJ/mol/nm)
:type convergence: float
:keyword actions: a list of actions to be executed periodically
(default is none)
:type actions: list
:keyword threads: the number of threads to use in energy evaluation
(default set by MMTK_ENERGY_THREADS)
:type threads: int
:keyword background: if True, the integration is executed as a
separate thread (default: False)
:type background: bool
"""
Minimizer.__init__(self, universe, options)
self.features = [Features.FixedParticleFeature,
Features.NoseThermostatFeature]
def __call__(self, **options):
"""
Run the minimizer. The keyword options are the same as described
under __init__.
"""
self.setCallOptions(options)
Features.checkFeatures(self, self.universe)
configuration = self.universe.configuration()
fixed = self.universe.getAtomBooleanArray('fixed')
nt = self.getOption('threads')
evaluator = self.universe.energyEvaluator(threads=nt).CEvaluator()
args =(self.universe,
configuration.array, fixed.array, evaluator,
self.getOption('steps'), self.getOption('step_size'),
self.getOption('convergence'), self.getActions(),
'Conjugate gradient minimization with ' +
self.optionString(['convergence', 'step_size', 'steps']))
return self.run(conjugateGradient, args)
|