def __call__(self, gradients=None, force_constants=None, small_change=False): self.checkUniverseVersion() args = [self.configuration.array] if ParticleProperties.isParticleProperty(gradients): args.append(gradients.array) elif isinstance(gradients, N.array_type): gradients = \ ParticleProperties.ParticleVector(self.universe, gradients) args.append(gradients.array) elif gradients: gradients = ParticleProperties.ParticleVector(self.universe, None) args.append(gradients.array) else: args.append(None) if ParticleProperties.isParticleProperty(force_constants): args.append(force_constants.array) elif isinstance(force_constants, N.array_type): force_constants = \ ParticleProperties.SymmetricPairTensor(self.universe, force_constants) args.append(force_constants.array) else: sparse_type = None try: from MMTK_forcefield import SparseForceConstants sparse_type = type(SparseForceConstants(2, 2)) except ImportError: pass if isinstance(force_constants, sparse_type): args.append(force_constants) elif force_constants: force_constants = \ ParticleProperties.SymmetricPairTensor(self.universe, None) args.append(force_constants.array) else: args.append(None) args.append(small_change) self.universe.acquireReadStateLock() try: energy = apply(self.evaluator, tuple(args)) finally: self.universe.releaseReadStateLock() if force_constants: return energy, gradients, force_constants elif gradients: return energy, gradients else: return energy
def __call__(self, gradients = None, force_constants = None, small_change=0): self.checkUniverseVersion() args = [self.configuration.array] if ParticleProperties.isParticleProperty(gradients): args.append(gradients.array) elif type(gradients) == Numeric.arraytype: gradients = \ ParticleProperties.ParticleVector(self.universe, gradients) args.append(gradients.array) elif gradients: gradients = ParticleProperties.ParticleVector(self.universe, None) args.append(gradients.array) else: args.append(None) if ParticleProperties.isParticleProperty(force_constants): args.append(force_constants.array) elif type(force_constants) == Numeric.arraytype: force_constants = \ ParticleProperties.SymmetricPairTensor(self.universe, force_constants) args.append(force_constants.array) else: sparse_type = None try: from MMTK_forcefield import SparseForceConstants sparse_type = type(SparseForceConstants(2, 2)) except ImportError: pass if type(force_constants) == sparse_type: args.append(force_constants) elif force_constants: force_constants = \ ParticleProperties.SymmetricPairTensor(self.universe, None) args.append(force_constants.array) else: args.append(None) args.append(small_change) self.universe.acquireReadStateLock() try: energy = apply(self.evaluator, tuple(args)) finally: self.universe.releaseReadStateLock() if force_constants: return energy, gradients, force_constants elif gradients: return energy, gradients else: return energy
def __call__(self, vector, gradients = None): conf = self.universe.configuration() g = None if gradients is not None: if ParticleProperties.isParticleProperty(gradients): g = gradients elif isinstance(gradients, N.array_type): g = ParticleProperties.ParticleVector(self.universe, gradients) elif gradients: g = ParticleProperties.ParticleVector(self.universe) if g is None: g_array = None else: g_array = g.array l = deformation(conf.array, vector.array, self.pairs, g_array, None, self.cutoff, self.fc_length, self.factor, 0, 1, self.version) if g is None: return l else: return l, g
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())