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 – a 3x3 rotation matrix describing the orientation (and/or inversion) to store

  • degrees – 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 – an optional axis about which the orientation can rotate. Only used if degrees is equal to 1

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)[source]

Compare two molecules by connectivity

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)[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

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)[source]

make graph object for the input molecule

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)[source]

Bases: object

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

Features: 0. Parse the input from different formats (SMILES, xyz, gjf, etc.). 1. Estimate molecular properties such as volume, tolerance, and radii. 2. Find and store symmetry information of the molecule. 3. Get the principal axis of the molecule. 4. 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 molecular tolerances.

  • symmetrize (bool, optional) – Whether to symmetrize the molecule using its 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. Defaults to a hex seed.

  • random_state (int or numpy.Generator, optional) – Numpy random state for random number generation.

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

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

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 the points cloud to describe the molecular box

Parameters:
  • center – molecular center position

  • orientation – orientation matrix

  • padding – padding of the box

  • resolution – float in angstrom

Returns:

box axis vertices: [N, 3] array, Cartesian coordinates to describe the box. center: box center

Return type:

cell

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 E = A*exp(-B*R) - C*R^(-6) according to Gavezotti, Acc. Chem. Res., 27, 1994 in Kcal/mol and angstrom

Parameters:
  • mol2 – the 2nd pyxtal_molecule object

  • tm – tolerance class

Returns:

a 3D matrix for computing the intermolecular energy

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]

For the given xyz, compute the orientation

Parameters:

xyz – molecular xyz

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:

xyz – 3D coordinates

Returns:

transition matrix:

Return type:

rmsd

get_symbols()[source]
get_symmetry(xyz=None, symmetrize=False, rtol=0.3)[source]
Set the molecule’s point symmetry.
  • pga: pymatgen.symmetry.analyzer.PointGroupAnalyzer object

  • pg: pyxtal.symmetry.Group object

  • symops: a list of SymmOp objects

Parameters:

symmetrize – boolean, whether or not symmetrize the coordinates

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

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(center=array([0., 0., 0.]), orientation=None)[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]

Allign a molecule so that its principal axes is the identity matrix.

Parameters:

mol – a Molecule object

Returns:

a reoriented copy of the original molecule. P: the 3x3 rotation matrix used to obtain it.

Return type:

new_mol