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
__init__(basename='cell', backend=None, logger=None, color=None, vdw_scale=1.0)

Create a Builder object

Parameters:
  • basename (str) – The base name for structure files created by this builder
  • backend (schrodinger.job.jobcontrol._Backend) – The job control backend we are running under, or None if not running under a backend
  • logger (logging.Logger) – The logger for this builder
  • color (str or None) – Set to module constant COLOR_BY_MOLECULE to color the structures in the cell by molecule
  • vdw_scale (float) – Scale factor for VdW radii during clash detection
buildingBlocksHaveRings()

Override in subclasses to check if any of the building blocks have rings. If none do, it will be a waste of time to look for them in the larger structure.

Return type:bool
Returns:If any of the building blocks have rings
checkForIntraStructureClashes(struct, scale=None, pbc=None, rings=None)

Check for any intrastructure clashes

Parameters:
  • struct (schrodinger.structure.Structure) – The structure for intrastructure clashes
  • scale (float) – The cutoff for finding clashes. This value is multipied times the sum of the VDW radii of the two atoms. If the distance is less than this scaled VDW radii sum, a clash exists
  • pbc (None, infrastructure.PBC, or list) –

    If periodic boundary conditions should be used, provide either an infrastructure.PBC object or the parameters to construct one. Allowed constructors:

    * a, b, c : box lengths
    * a, b, c, alpha, beta, gamma box : box lengths and angles
    * ax, ay, az, bx, by, bz, cx, cy, cz : box vectors
    
  • rings (list) – The precalculated rings returned by findRings() on the structure. If not supplied, they will be calculated on the fly.
Return type:

dict

Returns:

keys are atom indexes, and values are all the atom indexes that clash with that atom. A clash may come from two atoms too close together, or a ring that is speared by a bond.

colorByMolecule(struct)

Color each molecule in struct a different color

Parameters:struct (schrodinger.structure.Structure) – The structure to color
static countClashes(clashes)

Count the total number of clashes

Parameters:clashes (dict) – keys are atom indexes, values are all the atom indexes that clash with that atom
findRingSpears(ring_struct, spear_struct=None, rings=None, ring_based=True, pbc=None)

Find all cases where a bond spears a ring

Parameters:
  • ring_struct (schrodinger.structure.Structure) – The structure containing the rings
  • spear_struct (schrodinger.structure.Structure) – The structure containing the atoms that might spear the rings. If not provided, ring_struct will be used.
  • rings (list) – Each item of the list is a schrodinger.structure._Ring object. This is the list returned by the findRings() method. If not provided, they will be calculated on the fly - which takes considerable time. If findRingSpears will be run more than once on the same structure (even if the geometry changes), the rings should be precalculated via findRings and passed in via this parameter.
  • ring_based (bool) – Whether the returned dictionary should contain keys that are atom indexes of the speared ring (True), or of the bond spearing the ring (False)
  • pbc (None, infrastructure.PBC, or list) –

    If periodic boundary conditions should be used, provide either an infrastructure.PBC object or the parameters to construct one. Allowed constructors:

    * a, b, c : box lengths
    * a, b, c, alpha, beta, gamma box : box lengths and angles
    * ax, ay, az, bx, by, bz, cx, cy, cz : box vectors
    
Return type:

dict

Returns:

If ring_based=True, keys are an atom index of one of the atoms in the speared ring, and values are the atom index of one of the atoms in the spearing bond. If ring_based=False, the keys/values are flipped.

getClashes(struct1, cutoff, struct2=None, pbc=None, check_14=False)

Find clashes - either intrastructure if struct2 is None, or interstructure if struct2 is not None.

Parameters:
  • struct (schrodinger.structure.Structure) – The structure for intrastructure clashes or the first structure for interstructure clashes
  • cutoff (float) – The cutoff for finding clashes. This value is multipied times the sum of the VDW radii of the two atoms. If the distance is less than this scaled VDW radii sum, a clash exists
  • struct2 (schrodinger.structure.Structure) – The second structure for interstructure clashes
  • pbc (None, infrastructure.PBC, or list) –

    If periodic boundary conditions should be used, provide either an infrastructure.PBC object or the parameters to construct one. Allowed constructors:

    * a, b, c : box lengths
    * a, b, c, alpha, beta, gamma box : box lengths and angles
    * ax, ay, az, bx, by, bz, cx, cy, cz : box vectors
    
  • check_14 (bool) – If False, the atom pairs separated by 3 covalent bonds are excluded for clash check.
Return type:

dict

Returns:

keys are atom indexes in struct1 (or struct2 if defined), and values are all the atom indexes in struct1 that clash with that atom

getInfraStructure(struct)

Get an infrastructure Structure object and an associated bitset struct.atom_total long

Parameters:struct (schrodinger.structure.Structure) – The python module Structure object
Return type:tuple
Returns:First item of the tuple is a schrodinger.infra.structure.Structure object. Second item is a bitset that is struct.atom_total long
log(msg, level=20)

Log a message

Parameters:
  • msg (str) – The message to log
  • level (logging constant) – A log level constant from the logging module such as INFO, WARNING, ERROR…
removeIgnoredClashes(all_clashes, ignored_clashes)

Get only those clashes that are not ignored.

Parameters:
  • all_clashes (dict) – All found clashes
  • ignored_clashes (dict) – Clashes that should be ignored
Return type:

dict

Returns:

Those clashes in all_clashes that are not in ignored_clashes. Keys are atom indexes, values are all the atom indexes that clash with that atom

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 molecules
  • molnum (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 structure
  • cell (schrodinger.structure.Structure) – The structure containing the molecules to move via Monte Carlo
  • weight_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 class
  • cleanup (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 molecules
  • first (int) – The first valid molecule number to pick
  • last (int) – The last valid molecule number to pick
Return type:

MonteCarloMolecule

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(candidate, target=None)

Compute the total energy of the system

Parameters:
  • candidate (schrodinger.structure.Structure) – The entire cell containing all molecules
  • target (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