eproducer.ase_utils package

Molecular geometry tools built on top of ASE.

Submodules

eproducer.ase_utils.molecules

Molecular geometry tools built on top of ASE: alignment, transformation, PCA-based matching, and VMD-based connectivity extraction.

class eproducer.ase_utils.molecules.Alignment(atoms)[source]

Bases: object

Set of tools to apply the necessary transformations for aligning a the three first eigenvectors of PCA with the x, y, z axis, in that order.

Parameters:

atoms (ase.Atoms) – molecule to be aligned.

static align_with_components(atoms)[source]

Aligns the coordinates x, y, z axis with the main vectors (in that order).

Parameters:

atoms (ase.Atoms) – Molecule to be aligned.

Return type:

(ase.Atoms) rotated and shifted molecule.

static center_geo(atoms)[source]

Moves the coordinates origin to the geometrical center atoms.

Parameters:

atoms (ase.Atoms) – Molecule to be moved.

Return type:

(ase.Atoms) Transformed atoms

static pca_vectors(atoms, indexes='all')[source]

Find the eigen vectors in the Principal Component Analysis.

Parameters:
  • atoms (ase.Atoms) – molecule to be analyzed.

  • indexes (Default="all") – subset of atoms to be included in the pca analysis. numbering convention starting from 0.

Return type:

(array) principal components.

class eproducer.ase_utils.molecules.MoleculeSetter(atoms)[source]

Bases: object

Tool to edit or extract information from a molecule.

Parameters:

atoms (ase.Atoms) – molecule to be analyzed.

align_axis(vector)[source]

Computes the rotation matrix that aligns a vector with the positive x axis. The atoms are not modified.

Parameters:

vector (array) – vector to be aligned.

Return type:

(numpy.array) [3float x 3float] Transformation matrix.

align_plane(vector)[source]

Rotation around x axis to set a vector in the xy plane.

Parameters:

vector (array) – vector to be rotated to be in the xy plane.

Return type:

(numpy.array) [3float x 3float] Transformation matrix.

apply_trans(trans, indexes=None, shift=None)[source]

Apply a transformation to all vector positions of some atoms.

Parameters:
  • trans (array (3x3)) – transformation matrix to be applied to all atom positions.

  • indexes (list or array. Defatult=None) – indexes of the atoms to apply the transformation. Default None that means the transformation is applied to the positions of all the atoms.

  • shift (list. Default=None) – translation vector added after the transformation. It is applied to all the atoms, also to those not included in indexes.

Returns:

changes the positions of the internal atoms object.

Return type:

(list)[#natoms x 3float] new xyz positions of the N atoms. It

create_gaussian_input(out=None, charge=0, xc='bmk', basis='6-31+g')[source]

Creates a g09 .com file without specifing the kind of calculus to run (optimization, ab-initio md, frequencies…). You would have to add it.

Parameters:
  • out (str. Defatult=None) – name of the gaussian file (.com) without extension. Default chemical formula.

  • charge (int. Default=0) – charge of the molecule in electron units. Default 0.

  • xc (str. Default='bmk') – exchange correlation functional used in gaussian. Default bmk

  • basis (str. Default='6-31+g') – basis set used in gaussian. Default 6-31+g

Return type:

(ase.calculator.Gaussian) Calculator used to create the input.

increase_distance(constraints, deltad)[source]

increase the distance between two atoms by moving them and keeping the rest of the atoms in the same place.

Parameters:
  • constraints – constraints with the shape (n, 2), where n is the number of constraints and the first pair is the one to increase the distance.

  • deltad (float) – amount to add to the distance between atoms.

Return type:

(ase.Atoms) Internal Atoms object with the corresponding modification.

increase_distance_with_constraints(constraints, deltad)[source]

Take a configuration and increase the distance between two atoms by moving those atoms and the atoms connected to them through the other constraints, and keeping the rest of the atoms in the same place. The molecule is first centered and rotated such that the two atoms lie on the x axis (see MoleculeSetter.xy_alignment).

Parameters:
  • constraints – constraints with the shape (n, 2), where n is the number of constraints and the first pair is the one to increase the distance.

  • deltad (float) – amount to add to the distance between atoms.

Return type:

(ase.Atoms) Internal Atoms object with the corresponding modification.

rot_x(angle)[source]

Rotation matrix around x axis.

Parameters:

angle (float[radians]) – angle to rotate around the x axis

Return type:

(numpy.array) [3float x 3float] Rotation matrix.

rot_y(angle)[source]

Retuns the rotation matrix around y axis.

Parameters:

angle (float[radians]) – angle to rotate around the y axis

Return type:

(numpy.array) [3float x 3float] Rotation matrix.

rot_z(angle)[source]

Retuns the rotation matrix around z axis.

Parameters:

angle (float[radians]) – angle to rotate around the z axis

Return type:

(numpy.array) [3float x 3float] Rotation matrix.

scale_distance(constraints, deltad, index3=None)[source]

Increase the distance between two atoms by aligning those atoms with the x axis (the first atom at the origin) and scaling the x-coordinate of all the atoms.

Parameters:
  • constraints (list) – constraints with the shape (n, 2), where n is the number of constraints and the first pair is the one to increase the distance.

  • deltad (float) – amount to add to the distance between atoms.

  • index3 (int. Default=None) – The atom with index 3 would be in the xy plane in case to be given.

Returns:

  • (list)[#natoms x 3float] scaled xyz positions, before the rotation of

  • index3 into the xy plane. The internal atoms object is also modified

  • (including that rotation).

xy_alignment(index1, index2, index3=None, center=None)[source]

Transform the positions of the atoms such that the atoms of indexes1 and index2 are aligned in the x axis. The atom with index3 would be in the xy plane in case to be given.

Parameters:
  • index2 (index1 and) – indexes of the atoms to be aligned with the x-axis. The positive direction of x would go from atom 1 to atom 2.

  • index3 (int. Default=None) – The atom with index 3 would be in the xy plane in case to be given.

  • center (int. Default=None) – It must be index1 or index2, that means the atom with this index will be placed in the origin. In case center=None (default), the origin would be in the geometrical center between atoms with index1 and index2.

Returns:

changes the positions of the internal atoms object.

Return type:

(numpy.array)[#natoms x 3float] new xyz positions of the N atoms. It

class eproducer.ase_utils.molecules.PCAMatcher(reference, to_compare)[source]

Bases: object

Tools to align two molecules with their PCA main vectors.

Parameters:
  • reference (ase.Atoms) – reference of the molecule to be matched.

  • to_compare (ase.Atoms) – molecule to be compared to the reference.

align_molecules()[source]

Align each molecule with their own main PCA vectors.

Return type:

(tuple) aligned reference and molecule to compare.

matching()[source]

Finds the order of the indices of the molecule which fit with the atoms of the reference. So, if the outcome of this function is “out”, then PCAMatcher.to_compare[out[i]] == PCAMatcher.reference[i] should be true.

Returns:

  • (numpy.array) indices of the molecule that match the indices of the

  • reference.

Note

Both molecules are aligned (see PCAMatcher.align_molecules) before matching.

eproducer.ase_utils.molecules.vmd_connectivity(mol)[source]

Extracts the connectivity of a molecule using VMD.

Parameters:

mol (str) – path to a molecule file that VMD can read (e.g. xyz or pdb).

Returns:

  • (list) [n_atoms] list where the element i contains the indices of the

  • atoms bonded to the atom i. Indices start from 0 and every bond appears

  • twice (j in the list of i and i in the list of j).

Note

VMD must be available in the PATH. It uses ‘eproducer extract_bonds_vmd’.

eproducer.ase_utils.molecules.vmd_connectivity_matrix(mol)[source]

Builds the adjacency matrix of a molecule using the connectivity from VMD.

Parameters:

mol (str) – path to a molecule file that VMD can read (e.g. xyz or pdb).

Returns:

  • (numpy.array) [n_atoms x n_atoms] symmetric matrix with 1 where two atoms

  • are bonded and 0 otherwise.

eproducer.ase_utils.molecules.vmd_connectivity_unique(mol)[source]

Extracts the connectivity of a molecule using VMD, keeping each bond only once.

Parameters:

mol (str) – path to a molecule file that VMD can read (e.g. xyz or pdb).

Returns:

  • (list) [n_atoms] list where the element i contains the indices j > i of

  • the atoms bonded to the atom i. Indices start from 0.