pyxtal.molecule module

Module for handling molecules.

class pyxtal.molecule.Box(dims)[source]

Bases: object

Class for storing the binding box for a molecule.

Parameters:

dims – [length, width, height]

operate(rot=array([[1., 0., 0.], [0., 1., 0.], [0., 0., 1.]]), center=array([0., 0., 0.]))[source]

Perform operation on the box:

Parameters:
  • rot – 3*3 rotation matrix

  • center – center position

class pyxtal.molecule.Orientation(matrix=None, degrees=2, axis=None, random_state=None)[source]

Bases: object

Stores orientations for molecules based on vector constraints.

Can be stored to regenerate orientations consistent with a given constraint vector, without re-calling orientation_in_wyckoff_position. Allows for generating orientations which differ only in their rotation about a given axis.

Parameters:
  • matrix (ndarray) – A 3x3 rotation matrix describing the orientation (and/or inversion) to store

  • degrees (int) – The number of degrees of freedom: - 0: The orientation refers to a single rotation matrix - 1: The orientation can be rotated about a single axis - 2: The orientation can be any pure rotation matrix

  • axis (ndarray, optional) – Axis about which the orientation can rotate. Only used if degrees is equal to 1

  • random_state (int or Generator, optional) – Random number generator state

change_orientation(angle='random', flip=False, update=True)[source]

Change the orientation of molecule by applying a rotation.

It allows for specification of an angle (or a random angle) to rotate about the constraint axis. If the system has 2 degrees of rotational freedom, the molecule can also be flipped with a probability

Parameters:
  • angle (float or str, optional) – The angle to rotate about the constraint axis. If “random”, a random rotation angle is selected

  • flip (bool, optional) – Whether to apply an random flip. This is only applied if the system has 2 degrees of rotational freedom.

copy()[source]
get_Euler_angles()[source]

get the Euler angles

get_matrix(angle='random')[source]

Generate a 3x3 rotation matrix consistent with the orientation’s constraints. Allows for specification of an angle (possibly random) to rotate about the constraint axis.

Parameters:

angle – an angle to rotate about the constraint axis. If “random”, chooses a random rotation angle. If self.degrees==2, chooses a random 3d rotation matrix to multiply by. If the original matrix is wanted, set angle=0, or call self.matrix

Returns:

a 3x3 rotation (and/or inversion) matrix (numpy array)

get_op()[source]

Generate a SymmOp object consistent with the orientation’s constraints. Allows for specification of an angle (possibly random) to rotate about the constraint axis.

Parameters:

angle – an angle to rotate about the constraint axis. If “random”, chooses a random rotation angle. If self.degrees==2, chooses a random 3d rotation matrix to multiply by. If the original matrix is wanted, set angle=0, or call self.matrix

Returns:

pymatgen.core.structure. SymmOp object

classmethod load_dict(dicts)[source]
random_orientation()[source]

Applies random rotation (if possible) and returns a new orientation with the new base matrix.

Returns:

a new orientation object with a different base rotation matrix

reset_matrix(matrix)[source]
rotate_by_matrix(matrix, ignore_constraint=True)[source]

rotate

Parameters:

matrix – 3*3 rotation matrix

save_dict()[source]
set_axis()[source]
pyxtal.molecule.compare_mol_connectivity(mol1, mol2, ignore_name=False, ignore_HH=False, debug=False)[source]

Compare two molecules by connectivity

Parameters:
  • mol1 – pymatgen Molecule object

  • mol2 – pymatgen Molecule object

  • ignore_name (bool) – If True, ignore the atom names in the comparison

  • ignore_HH (bool) – If True, ignore the H-H bonds in the comparison

Returns:

(is_isomorphic, mapping)
  • is_isomorphic (bool): True if the two molecules are isomorphic

  • mapping (dict): A dictionary mapping nodes from mol1 to mol2

Return type:

tuple

pyxtal.molecule.find_rotor_from_smile(smile)[source]

Find the positions of rotatable bonds based on a SMILES string.

Rotatable bonds are those which are not part of rings and which fit specific chemical patterns. These torsions are filtered by rules such as avoiding atoms with only one neighbor and avoiding equivalent torsions.

Parameters:

smile (str) – The SMILES string representing the molecule.

Returns:

Each tuple represents a torsion as (i, j, k, l) where i-j-k-l are atom indices involved in the rotatable bond.

Return type:

list of tuples

pyxtal.molecule.generate_molecules(smile, wps=None, N_iter=5, N_conf=10, tol=0.5, use_uff=False)[source]

generate pyxtal_molecules from smiles codes.

Parameters:
  • smile – smiles code

  • wps – list of wps

  • N_iter – rdkit parameter

  • N_conf – number of conformers

  • tol – rdkit parameter

  • use_uff – whether to use UFF for force field optimization

Returns:

a list of pyxtal molecules

pyxtal.molecule.get_inertia_tensor(coords, weights=None)[source]

Calculate the symmetric inertia tensor for a molecule.

Parameters:

coords – [N, 3] array of coordinates

Returns:

a 3x3 numpy array representing the inertia tensor

pyxtal.molecule.has_non_aromatic_ring(smiles)[source]

Determine if a molecule has a non-aromatic ring. It checks if a cyclic ring system exists that is not aromatic.

Parameters:

smiles (str) – A SMILES string representing the molecule.

Returns:

True if it contains a non-aromatic ring, False otherwise.

Return type:

bool

pyxtal.molecule.is_compatible_symmetry(mol, wp)[source]

Tests if a molecule meets the symmetry requirements of a Wyckoff position

Parameters:
  • mol – a pymatgen Molecule object.

  • wp – a pyxtal.symmetry.Wyckoff_position object

pyxtal.molecule.make_graph(mol, tol=0.2, ignore_HH=False, debug=False)[source]

make graph object for the input molecule

Parameters:
  • mol – pymatgen Molecule object

  • tol (float) – Tolerance for bond length matching

  • ignore_HH (bool) – If True, ignore H-H bonds

Returns:

a networkx Graph object representing the molecule’s connectivity

Return type:

G

class pyxtal.molecule.pyxtal_molecule(mol=None, symmetrize=True, fix=False, torsions=None, seed=None, random_state=None, tm=<pyxtal.tolerance.Tol_matrix object>, symtol=0.3, active_sites=None, use_uff=False)[source]

Bases: object

A molecule class to support the descriptin of molecules in a xtal

Features:
  • Parse the input from different formats (SMILES, xyz, gjf, etc.).

  • Estimate molecular properties such as volume, tolerance, and radii.

  • Find and store symmetry information of the molecule.

  • Get the principal axis of the molecule.

  • Re-align the molecule to center it at (0, 0, 0).

SMILES Format: If a SMILES format is used, the molecular center is defined following RDKit’s handling of molecular transformations: https://www.rdkit.org/docs/source/rdkit.Chem.rdMolTransforms.html

Otherwise, the center is just the mean of atomic positions

Parameters:
  • mol (str or pymatgen.Molecule) – The molecule representation, either as a string (SMILES or filename) or as a pymatgen Molecule object.

  • tm (Tol_matrix, optional) – A tolerance matrix object, used for bond checking.

  • symmetrize (bool, optional) – Whether to symmetrize the molecule by point group.

  • fix (bool, optional) – Fix torsions in the molecule.

  • torsions (list, optional) – List of torsions to analyze or fix.

  • seed (int, optional) – Random seed for internal processes.

  • random_state (int or numpy.Generator, optional) – state for random seed.

  • symtol (float, optional) – Symmetry tolerance. Default is 0.3.

  • active_sites (list, optional) – List of active sites within the molecule.

  • use_uff (bool, optional) – Use UFF for force field. Default is False.

align(conf, reflect=False, torsionlist=None)[source]

Align the molecule and return the xyz The default CanonicalizeConformer function may also include inversion

apply_inversion()[source]

reset the coordinates

copy()[source]

simply copy the structure

get_box(padding=None)[source]

Given a molecule, find a minimum orthorhombic box containing it. Size is calculated using min and max x, y, and z values, plus the padding defined by the vdw radius For best results, call oriented_molecule first.

Parameters:

padding – float (default is 3.4 according to the vdw radius of C)

Returns:

a Box object

Return type:

box

get_box_coordinates(xyz, padding=0, resolution=1.0)[source]

Create points cloud to describe the molecular box.

Parameters:
  • xyz (ndarray) – Coordinates of the molecule

  • padding (float, optional) – Padding distance around the box. Default is 0.

  • resolution (float) – Grid resolution in angstroms. Default is 1.0.

Returns:

  • cell (ndarray): Box axis vectors

  • vertices (ndarray): [N,3] array of box vertices in Cartesian coordinates

  • center (ndarray): Box center coordinates

Return type:

tuple

get_center(xyz, geometry=False)[source]

get the molecular center for a transformed xyz

get_coefs_matrix(mol2=None, ignore_error=True)[source]

Get the Atom-Atom potential parameters between two molecules.

Calculates coefficients A, B, C for the potential energy equation:

E = A*exp(-B*R) - C*R^(-6)

Parameters are from Gavezotti, Acc. Chem. Res., 27, 1994.

Parameters:
  • mol2 (pyxtal_molecule, optional) – Second molecule to calculate interaction with. If None, uses same molecule.

  • ignore_error (bool) – Whether to ignore errors for unsupported atoms. Defaults to True.

Returns:

Array of shape (n_atoms1, n_atoms2, 3) containing A, B, C coefficients for each atom pair. These are used to compute the intermolecular energy. Units are Kcal/mol and angstrom.

Return type:

ndarray

get_energy(xyz1, xyz2)[source]

Get packing energy between two neighboring molecules

get_lengths()[source]
get_max_length()[source]
get_orientation(xyz, rtol=0.15)[source]

Get the orientation for the given xyz coordinates.

Parameters:
  • xyz (ndarray) – Molecular coordinates

  • rtol (float, optional) – Relative tolerance. Defaults to 0.15.

Returns:

  • array: Euler angles in degrees [alpha, beta, gamma]

  • float: RMSD from reference orientation

  • bool: Whether reflection was applied

Return type:

tuple

get_orientations_in_wp(wp, rtol=0.01)[source]

Compute the valid orientations from a given Wyckoff site symmetry.

Parameters:

wp – a pyxtal.symmetry.Wyckoff_position object

Returns:

a list of pyxtal.molecule.Orientation objects

get_orientations_in_wps(wps=None, rtol=0.01)[source]

Compute the valid orientations from a given Wyckoff site symmetry.

Parameters:

wp – a pyxtal.symmetry.Wyckoff_position object

Returns:

a list of operations.Orientation objects

get_principle_axes(xyz, rdmt=True)[source]

Get the principle axis for a rotated xyz, sorted by the moments.

get_radius()[source]

get the radius of a molecule

get_rmsd(xyz, debug=False)[source]

Compute the rmsd with another 3D xyz coordinates

Parameters:

xyz – 3D coordinates

Returns:

rmsd values transition matrix: 4*4 matrix match: True or False

Return type:

rmsd (float)

get_rmsd2(xyz0, xyz1)[source]

Compute the rmsd with another 3D xyz coordinates.

Parameters:
  • xyz0 (ndarray) – First set of atomic coordinates

  • xyz1 (ndarray) – Second set of atomic coordinates

Returns:

  • rmsd (float): Root mean square deviation between the coordinates

  • trans (ndarray): 4x4 transformation matrix that maps xyz0 onto xyz1

Return type:

tuple

get_symbols()[source]
get_symmetry(xyz=None, symmetrize=False, rtol=0.3)[source]

Set the molecule’s point symmetry.

Sets the following attributes:
  • pga: Point group analyzer from pymatgen

  • pg: Point group from pyxtal

  • symops: List of symmetry operations

Parameters:
  • xyz (ndarray, optional) – Coordinates to analyze. Defaults to current coordinates.

  • symmetrize (bool, optional) – Whether to symmetrize coordinates. Defaults to False.

  • rtol (float, optional) – Symmetry tolerance. Defaults to 0.30.

get_tols_matrix(mol2=None, tm=None)[source]

Compute the 2D tolerance matrix between the current and other molecules

Parameters:
  • mol2 – the 2nd pyxtal_molecule object

  • tm – tolerance class

Returns:

a 2D matrix which is used internally for distance checking.

get_torsion_angles(xyz=None, torsionlist=None)[source]

Get the torsion angles for the molecule.

Parameters:
  • xyz (ndarray, optional) – Coordinates to compute angles for. If None, uses current molecular coordinates.

  • torsionlist (list, optional) – List of torsion definitions. If None, uses molecule’s torsionlist.

Returns:

List of torsion angles in degrees. Returns empty list if no torsions defined.

Return type:

list

list_molecules()[source]

list the internally supported molecules

classmethod load_str(string)[source]

load the molecule from a dictionary

perturb_torsion(xyz)[source]

slightly perturb the torsion

rdkit_mol(N_confs=1)[source]

Initialize the mol xyz and torsion list

rdkit_mol_init(smile, fix, torsions)[source]

Initialize the mol xyz and torsion list

Parameters:
  • smile – smile string

  • fix – whether or not fix the seed

  • torsions – None or list

relax(xyz, align=False)[source]

Relax the input xyz coordinates with rdit MMFF

Parameters:
  • xyz – 3D coordinates

  • align – whether or not align the xyz

Returns:

new xyz eng: energy value

Return type:

xyz

reset_positions(coors)[source]

reset the coordinates

save_str()[source]

save the object as a dictionary

set_labels()[source]

Set atom labels for the given molecule for H-bond caculation. Needs to identify the following:

  • (O)N-H

  • acid-O

  • amide-O

  • alcohol-O

  • N with NH2

  • N with NH

set_torsion_angles(conf, angles, reflect=False, torsionlist=None)[source]

Reset the torsion angles and update molecular xyz

show()[source]

show the molecule

show_box()[source]

Show the molecule.

swap_axis(ax)[source]

swap the molecular axis

to_ase()[source]

Convert to ase atoms

pyxtal.molecule.reoriented_molecule(mol)[source]

Align a molecule so that its principal axes are aligned with the coordinate axes.

Reorients the molecule by computing its inertia tensor and rotating it such that the principal axes align with the x, y, z coordinate axes.

Parameters:

mol (Molecule) – A pymatgen Molecule object to reorient.

Returns:

  • mol (Molecule): A reoriented copy of the input molecule

  • P (ndarray): The 3x3 rotation matrix used to align the molecule

Return type:

tuple