schrodinger.application.matsci.montecarlo module¶
Classes related to Monte Carlo simulations
Copyright Schrodinger, LLC. All rights reserved.
- class schrodinger.application.matsci.montecarlo.ClashChecker(basename='cell', backend=None, logger=None, color=None, vdw_scale=1.0)¶
Bases:
schrodinger.application.matsci.amorphous.BuilderWithClashDetection
A builder used just for checking for clashes during Monte Carlo simulations
- checkForRings(struct)¶
Check for rings in struct and cache them
- Parameters
struct (
schrodinger.structure.Structure
) – The structure to check for rings
- findRings(struct)¶
Return the cache of found rings - struct is not used because the structure may change coordinates but never bonding during an MC run. It is kept for API compatibility with the parent class.
- Parameters
struct – unused
- Return type
list
- Returns
The list of found rings
- class schrodinger.application.matsci.montecarlo.MonteCarloMolecule(cell, molnum, box)¶
Bases:
object
Class for treatment of a moving molecule during a Monte Carlo iteration
- __init__(cell, molnum, box)¶
Create a MonteCarloMolecule object
- Parameters
cell (
schrodinger.structure.Structure
) – The complete cell of moleculesmolnum (int) – The molecule number that will be moved
- randomlyRotate(max_degrees)¶
Randomly rotate the molecule by no more than the given number of degrees
- Parameters
max_degrees (float) – The largest rotation allowed
- randomlyTranslate(mu_sigma)¶
Randomly translate the molecule. The distribution of translation distances is given by a lognormal distribution.
- Parameters
mu_sigma ((float, float)) – (mu, sigma). mu gives the mean value of the lognormal distribution the translation is taken from. sigma gives the standard deviation of the distribution
- updateCoordinates()¶
Update the coordinates of this molecule within the entire cell
- getCoordinates()¶
Get the xyz coordinate for this molecule
- Return type
numpy.array
- Returns
The xyz coordinates of this molecule
- class schrodinger.application.matsci.montecarlo.Metropolizer(scaffold, cell=None, weight_rotate=0.5, weight_translate=0.5, translate_mu=0.25, translate_sigma=1.0, max_rotate=360.0, temperatures=None, iterations=10000, clash_penalty=50.0, minimize_interval=None, forcefield=14, vdw_scale=1.0, gravity=True, gravity_weight=4.0, logger=None, cleanup=True)¶
Bases:
object
A class that runs a Monte Carlo simulation using the Metropolis algorithm
- ROTATE = 0¶
- TRANSLATE = 1¶
- __init__(scaffold, cell=None, weight_rotate=0.5, weight_translate=0.5, translate_mu=0.25, translate_sigma=1.0, max_rotate=360.0, temperatures=None, iterations=10000, clash_penalty=50.0, minimize_interval=None, forcefield=14, vdw_scale=1.0, gravity=True, gravity_weight=4.0, logger=None, cleanup=True)¶
Create a Metropolizer object
- Parameters
scaffold (
amorphous.Scaffold
) – The scaffold object that controls the cell structurecell (
schrodinger.structure.Structure
) – The structure containing the molecules to move via Monte Carloweight_rotate (float) – The weight of rotation when randomly choosing to rotate or translate
weight_translate (float) – The weight of translations when randomly choosing to rotate or translate
translate_mu (float) – The mean of the natural logarithm function for the log-normal distribution of translation distances.
translate_sigma (float) – The standard deviation of the natural logarithm function for the log-normal distribution of translation distances.
max_rotate (float) – The maximum number of degrees for any rotation
temperatures (list of float) – A list of temperatures to run the annealing at
iterations (int) – The number of Monte Carlo iterations to run at each temperature
clash_penalty (float) – Penalty for clashes
minimize_interval (int) – Do a minimization after every Xth interval. Not implemented at this time.
forcefield (int or None) – The mmffld number of the forcefield to use for energy evaluations. Use None to turn off forcefield energy evaluations.
vdw_scale (float) – The VdW scale factor to use for clash checking
gravity (bool) – Whether to use the gravity term. Gravity attracts all molecules toward the scaffold if a scaffold molecule is present, or the center of the cell if no scaffold is present. If no forcefield term is included, then a simple hard shell model is used to prevent clashes caused by gravity.
logger (
logging.Logger
) – The logger for this classcleanup (bool) – Attempt to clean up the Lewis structure before evaluating the energy. Only relevant if forcefield is not None.
- setupGravity()¶
Pre-compute data for the gravity term
- getNumClashes(struct)¶
Get the number of clashes for the proposed structure
- Parameters
struct (
schrodinger.structure.Structure
) – The structure to check for clashes- Return type
int
- Returns
The total number of clashes found
- getClosestApproach(coords)¶
Get the closest approach between the given set of coordinates and the scaffold molecule or gravity center if no scaffold.
- Parameters
coords (
numpy.array
) – The XYZ coordinates to check for close approach to the scaffold - such as from the getXYZ()- Return type
float
- Returns
The closest approach between coords and the scaffold, or the gravity center if no scaffold was used.
- getGravityEnergy(target)¶
Evaluate the gravitational energy of the given target. The energy is simply the difference of the original distance between the target and the gravitational source and the new distance between them.
- Parameters
target (
MonteCarloMolecule
) – A molecule that has been randomly moved- Return type
float
- Returns
The gravitational energy of the target’s new position
- getClashPenalty(candidate)¶
Get the energy penalty due to clashes
- Parameters
candidate (
schrodinger.structure.Structure
) – The structure to check for clashes- Return type
float
- Returns
The penalty based on the number of clashes
- simulate()¶
Run the Monte Carlo simulated annealing
- getTargetMolecule(candidate, first, last)¶
Select the molecule to move this iteration
- Parameters
candidate (
schrodinger.structure.Structure
) – The entire cell containing all moleculesfirst (int) – The first valid molecule number to pick
last (int) – The last valid molecule number to pick
- Return type
- Returns
The MCM object for the chosen molecule
- findFirstDisorderedMolecule()¶
Find the first molecule number that isn’t part of the scaffold
- Return type
int
- Returns
The first non-scaffold molecule number
- getEnergy(minimizer, candidate, target=None)¶
Compute the total energy of the system
- Parameters
candidate (
schrodinger.structure.Structure
) – The entire cell containing all moleculestarget (
MonteCarloMolecule
) – The MCM object for the just-moved molecule (None if this is the 0th iteration
- Return type
(float, float, float, float)
- Returns
The total energy, forcefield energy, gravitational energy and clash energy (total energy is the sum of the last three)
- isAccepted(old_energy, new_energy)¶
Use the Metropolis equation to determine if the move is accepted
- Parameters
old_energy (float) – The previous energy
new_energy (float) – The new energy
- Return type
bool
- Returns
Whether the move is accepted or not
- performMovement(target)¶
Move the molecule randomly
- Parameters
target (
MonteCarloMolecule
) – The MCM object to move- Return type
int
- Returns
A class constant indicating whether the move was ROTATE or TRANSLATE
- log(msg, level=20)¶
Add a message to the log file
- Parameters
msg (str) – The message to add
level (int) – A
logging
priority level of the message