This module defines general-purpose objects, functions and classes.
Functions, classes, etc. defined here should not depend on any other
part of stk. They must be completely self-sufficient.
-
class
Cell(id_, fgs)¶ Bases:
objectRepresents an individual cell in a supercell.
- Parameters
id (
listofint) – A 3 memberlistholding the x, y and z index of the cell within the supercell.fgs (
dict) – Maps the fgs in the original unit cell to the equivalent fgs in the cell.
-
id¶ A 3 member array holding the x, y and z index of the cell within the supercell.
- Type
numpy.ndarrayofint
-
fgs¶ Maps the fgs in the original unit cell to the equivalent fgs in the cell.
- Type
dict
-
__init__(self, id_, fgs)¶ Initialize self. See help(type(self)) for accurate signature.
-
exception
ChargedMolError(mol_file, msg)¶ Bases:
Exception-
__init__(self, mol_file, msg)¶ Initialize self. See help(type(self)) for accurate signature.
-
args¶
-
with_traceback()¶ Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
-
-
class
LazyAttr(func)¶ Bases:
objectA descriptor for creating lazy attributes.
-
__init__(self, func)¶ Initialize self. See help(type(self)) for accurate signature.
-
-
class
MAEExtractor(run_name, n=1)¶ Bases:
objectExtracts the lowest energy conformer from a .maegz file.
Macromodel conformer searches produce -out.maegz files containing all of the conformers found during the search and their energies and other data.
Initializing this class with a
ConstructedMoleculefinds the-out.maegzfile of thatConstructedMoleculeand converts it to a.maefile. It then creates and additional.maefile holding only the lowest energy conformer found.-
maegz_path¶ The path to the
-out.maegzfile generated by the macromodel conformer search.- Type
str
-
mae_path¶ The path to the
.maefile holding the conformers generated by the macromodel conformer search.- Type
str
-
content¶ The content of the
.maefile hodling all the conformers from the macromodel conformer search. This holds other data such as their energies too.- Type
str
-
energies¶ The
listhas the formenergies = [(0, 231.0), (1, 144.4), ...]
Each
tupleholds the id and energy of every conformer in the.maefile, respectively.- Type
list
-
min_energy¶ The minimum energy found in the
.maefile.- Type
float
-
path¶ The full path of the
.maefile holding the extracted lowest energy conformer.- Type
str
Methods
extract_conformers(self, n)Creates
.maefiles holding the lowest energy conformers.extract_energy(self, block)Extracts the energy value from a
.maeenergy data block.lowest_energy_conformers(self, n)Returns the id and energy of the lowest energy conformers.
maegz_to_mae(self)Converts the .maegz file to a .mae file.
-
__init__(self, run_name, n=1)¶ Initialize self. See help(type(self)) for accurate signature.
-
extract_conformers(self, n)¶ Creates
.maefiles holding the lowest energy conformers.- Parameters
n (
int) – The number of conformers to extract.- Returns
None
- Return type
NoneType
-
extract_energy(self, block)¶ Extracts the energy value from a
.maeenergy data block.- Parameters
block (
str) – An.maeenergy data block.- Returns
The energy value extracted from block or
Noneif one is not found.- Return type
float
-
lowest_energy_conformers(self, n)¶ Returns the id and energy of the lowest energy conformers.
- Parameters
n (
int) – The number of lowest energy conformers to return.- Returns
A
listof the formreturned = [(23, 123.3), (1, 143.89), (12, 150.6), ...]
Where each
tupleholds the id and energy of the n lowest energy conformers, respectively.- Return type
list
-
maegz_to_mae(self)¶ Converts the .maegz file to a .mae file.
- Returns
None
- Return type
NoneType
-
-
exception
MolFileError(mol_file, msg)¶ Bases:
Exception-
__init__(self, mol_file, msg)¶ Initialize self. See help(type(self)) for accurate signature.
-
args¶
-
with_traceback()¶ Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
-
-
exception
PopulationSizeError(msg)¶ Bases:
Exception-
__init__(self, msg)¶ Initialize self. See help(type(self)) for accurate signature.
-
args¶
-
with_traceback()¶ Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
-
-
class
XTBExtractor(output_file)¶ Bases:
objectExtracts properties from GFN-xTB output files.
-
output_file¶ Output file to extract properties from.
- Type
str
-
output_lines¶ listof all lines in asstrin the output file.- Type
list:str
-
total_energy¶ The total energy in the
output_fileasfloat. The energy is in units of a.u..- Type
float
-
homo_lumo_gap¶ The HOMO-LUMO gap in the
output_fileasfloat. The gap is in units of eV.- Type
float
-
fermi_level¶ The Fermi level in the
output_fileasfloatin units of eV.- Type
float
-
qonly_dipole_moment¶ Components of the Q only dipole moment in units of Debye in
listof the form[x, y, z].- Type
list
-
full_dipole_moment¶ Components of the full dipole moment in units of Debye in
listof the form[x, y, z, total].- Type
list
-
qonly_quadrupole_moment¶ Components of the Q only traceless quadrupole moment in units of Debye in
listof the form[xx, xy, xy, xz, yz, zz].- Type
list
-
qdip_quadrupole_moment¶ Components of the Q+Dip traceless quadrupole moment in units of Debye in
listof the form[xx, xy, xy, xz, yz, zz].- Type
list
-
full_quadrupole_moment¶ Components of the full traceless quadrupole moment in units of Debye in
listof the form[xx, xy, xy, xz, yz, zz].- Type
list
-
homo_lumo_occ¶ dictoflistcontaining the orbital number, energy in eV and occupation of the HOMO and LUMO orbitals in theoutput_file.- Type
dict
-
total_free_energy¶ The total free energy in the
output_fileasfloat. The free energy is in units of a.u. and calculated at 298.15K.- Type
float
-
frequencies¶ listof the vibrational frequencies asfloatin theoutput_file. Vibrational frequencies are in units of wavenumber and calculated at 298.15K.- Type
list
-
__init__(self, output_file)¶ Initializes
XTBExtractor- Parameters
output_file (
str) – Output file to extract properties from.
-
-
exception
XTBInvalidSolventError¶ Bases:
Exception-
__init__(self, /, *args, **kwargs)¶ Initialize self. See help(type(self)) for accurate signature.
-
args¶
-
with_traceback()¶ Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
-
-
archive_output()¶ Places the
outputfolder intostk_ea_runs.This function assumes that the
outputfolder is in the current working directory.- Returns
None
- Return type
NoneType
-
dedupe(iterable, key=None, seen=None)¶ Yields items from iterable barring duplicates.
If seen is provided it contains elements which are not to be yielded at all.
- Parameters
iterable (
iterable) – An iterable of elements which are to be yielded, only once.key (
callable) – A function which gets applied to every member of iterable. The return of this function is checked for duplication rather than the member itself.seen (
set, optional) – Holds items which are not to be yielded.
- Yields
object– Element in iterable which is not in seen and has not been yielded before.
-
dice_similarity(mol1, mol2, fp_radius=3)¶ Return the chemical similarity between two molecules.
-
flatten(iterable, excluded_types=None)¶ Transforms an nested iterable into a flat one.
For example
[[1,2,3], [[4], [5],[[6]], 7]
becomes
[1,2,3,4,5,6,7]
If a type is found in excluded_types it will not be yielded from. For example if
stris in excluded_typesa = ["abcd", ["efgh"]]
“abcd” and “efgh” are yielded if a is passed to iterable. If str was not in excluded_types then “a”, “b”, “c”, “d”, “e”, “f”, “g” and “h” would all be yielded individually.
- Parameters
iterable (
iterable) – The iterable which is to be flattenedexcluded_types (
set, optional) – Holds container types which are not be flattened.
- Yields
object– A nested element of iterable.
-
is_valid_xtb_solvent(gfn_version, solvent)¶ Check if solvent is valid for the given GFN version.
- Parameters
gfn_version (
int) – GFN parameterization version. Can be:0,1or2.solvent (
str) – Solvent being tested [1].
- Returns
Trueif solvent is valid.- Return type
bool
References
-
kabsch(coords1, coords2)¶ Return a rotation matrix to minimize dstance between 2 coord sets.
This is essentially an implementation of the Kabsch algorithm. Given two sets of coordinates, coords1 and coords2, this function returns a rotation matrix. When the rotation matrix is applied to coords1 the resulting coordinates have their rms distance to coords2 minimized.
- Parameters
coords1 (
numpy.ndarray) – This array represents a matrix hodling coordinates which need to be rotated to minimize their rms distance to coordinates in coords2. The matrix is n x 3. Each row of the matrix holds the x, y and z coordinates of one point, respectively. Herenis the number of points.coords2 (
numpy.ndarray) – This array represents a matrix which holds the coordinates of points the distance to which should be minimized. The matrix isn x 3. Each row of the matrix holds the x, y and z coordinates of one point, respectively. Herenis the number of points.
- Returns
A rotation matrix. This will be a
3 x 3matrix.- Return type
numpy.ndarray
References
http://nghiaho.com/?page_id=671 https://en.wikipedia.org/wiki/Kabsch_algorithm
-
kill_macromodel()¶ Kills any applications left open as a result running MacroModel.
Applications that are typically left open are
jserver-watcher.exeandjservergo.exe.- Returns
None
- Return type
NoneType
-
matrix_centroid(matrix)¶ Returns the centroid of the coordinates held in matrix.
- Parameters
matrix (
np.ndarray) – An x 3matrix. Each row holds the x, y and z coordinate of some point, respectively.- Returns
A numpy array which holds the x, y and z coordinates of the centroid of the coordinates in matrix.
- Return type
numpy.ndarray
-
mol_from_mae_file(mae_path)¶ Creates a
rdkitmolecule from a.maefile.- Parameters
mol2_file (
str) – The full path of the.maefile from which an rdkit molecule should be instantiated.- Returns
An
rdkitinstance of the molecule held in mae_file.- Return type
rdkit.Mol
-
mol_from_mol_file(mol_file)¶ Creates a rdkit molecule from a
.mol(V3000) file.- Parameters
mol_file (
str) – The full of the .mol file from which an rdkit molecule should be instantiated.- Returns
An rdkit instance of the molecule held in mol2_file.
- Return type
rdkit.Mol- Raises
ChargedMolError – If an atom row has more than 8 coloumns it is usually because there is a 9th coloumn indicating atomic charge. Such molecules are not currently supported, so an error is raised.
MolFileError – If the file is not a V3000
.molfile.
-
move_generated_macromodel_files(basename, output_dir)¶
-
normalize_vector(vector)¶ Normalizes the given vector.
A new vector is returned, the original vector is not modified.
- Parameters
vector (
np.ndarray) – The vector to be normalized.- Returns
The normalized vector.
- Return type
np.ndarray
-
orthogonal_vector(vector)¶
-
quaternion(u)¶ Returns a translation + rotation quaternion.
- Parameters
u (
listoffloat) – Alistof length 3 holding the parameter for the quarternion.
References
K. Shoemake, Uniform random rotations, Graphics Gems III, pages 124-132. Academic, New York, 1992.
-
remake(mol)¶ Remakes a molecule from scratch.
- Parameters
mol (
rdkit.Mol) – The molecule to be remade.- Returns
The remade molecule.
- Return type
rdkit.Mol
-
rotation_matrix(vector1, vector2)¶ Returns a rotation matrix which transforms vector1 to vector2.
Multiplying vector1 by the rotation matrix returned by this function yields vector2.
- Parameters
vector1 (
numpy.ndarray) – The vector which needs to be transformed to vector2.vector2 (
numpy.ndarray) – The vector onto which vector1 needs to be transformed.
- Returns
A rotation matrix which transforms vector1 to vector2.
- Return type
numpy.ndarray
References
-
rotation_matrix_arbitrary_axis(angle, axis)¶ Returns a rotation matrix of angle radians about axis.
- Parameters
angle (
float) – The size of the rotation in radians.axis (
numpy.ndarray) – A 3 element aray which represents a vector. The vector is the axis about which the rotation is carried out.
- Returns
A
3x3array representing a rotation matrix.- Return type
numpy.ndarray
-
tar_output()¶ Places all the content in the
outputfolder into a .tgz file.- Returns
None
- Return type
NoneType
-
time_it()¶ Times the code executed within the indent.
This is a context manager so it should be used as:
with time_it(): something1() something2() something3()
After all 3 functions are finished and the nested block is exited the time taken to process the entire block is printed.
-
translation_component(q)¶ Extracts translation vector from quaternion.
- Parameters
q (
numpy.ndarray) – A length 4 quaternion.- Returns
The translation vector encoded within q.
- Return type
numpy.ndarray
-
vector_angle(vector1, vector2)¶ Returns the angle between two vectors in radians.
- Parameters
vector1 (
numpy.ndarray) – The first vector.vector2 (
numpy.ndarray) – The second vector.
- Returns
The angle between vector1 and vector2 in radians.
- Return type
float