Geometry
class#
- class AaronTools.geometry.Geometry(structure='', name='', comment='', components=None, refresh_connected=True, refresh_ranks=True)#
- Attributes:
name comment atoms other _iter_idx
- __init__(structure='', name='', comment='', components=None, refresh_connected=True, refresh_ranks=True)#
- Parameters:
structure – can be a Geometry(), a FileReader(), a file name, or a list of atoms
name (str) – name
comment (str) – comment
components (list(AaronTools.component.Component())|None) – components list or None
refresh_connected (bool) –
usually True - determine connectivity
can save time for methods that only need coordinates by using refresh_connected=False
refresh_ranks (bool) – usually True - rank atoms, False when loading from database can save time for methods that only don’t rely on ranks by using refresh_ranks=False
- static iupac2smiles(name)#
convert IUPAC name to smiles using the OPSIN web API
- Parameters:
name (str) – IUPAC name of a molecule
- classmethod from_string(name, form='smiles', strict_use_rdkit=False)#
get Geometry from string
- Parameters:
name (str) – either an IUPAC name or a SMILES for a molecule
form (str) –
“smiles” - structure from cactvs API/RDKit
”iupac” - iupac to smiles from opsin API, then the same as form=smiles
strict_use_rdkit (bool) – force use of RDKit and never use cactvs
- classmethod get_coordination_complexes(center, ligands, shape, c2_symmetric=None, minimize=False, session=None)#
get all unique coordination complexes uses templates from Inorg. Chem. 2018, 57, 17, 10557–10567
- Parameters:
center (str) –
element of center atom
ligands (list(str)) –
list of ligand names in the ligand library
shape (str) – coordination geometry (e.g. octahedral) - see Atom.get_shape
c2_symmetric (list(bool)) – specify which of the bidentate ligands are C2-symmetric if this list is as long as the ligands list, the nth item corresponds to the nth ligand otherwise, the nth item indicate the symmetry of the nth bidentate ligand
minimize (bool) – passed to cls.map_ligand when adding ligands
- Returns:
a list of cls containing all unique coordination complexes and the general formula of the complexes
- Return type:
list(Geometry)
- classmethod get_diastereomers(geometry, minimize=True)#
- static weighted_percent_buried_volume(geometries, energies, temperature, *args, **kwargs)#
Boltzmann-averaged percent buried volume
- Parameters:
geometries (list(Geometry)) – structures to calculate buried volume for
energies (np.ndarray) – energy in kcal/mol; ith energy corresponds to ith substituent
temperature – temperature in K
args (float) – passed to Geometry.percent_buried_volume()
kwargs – passed to Geometry.percent_buried_volume()
- Returns:
Boltzmann-weighted percent buried volume
- property elements#
returns list of elements composing the atoms in the geometry
- property num_atoms#
number of atoms
- property coords#
array of coordinates (read only)
- coordinates(atoms=None)#
- Parameters:
atoms (list(Atom)) –
- Returns:
N x 3 coordinate matrix for requested atoms (defaults to all atoms)
- Return type:
np.ndarray
- write(name=None, *args, **kwargs)#
Write geometry to a file
- Parameters:
name (str) – name for geometry defaults to self.name
args – passed to FileWriter.write
kwargs – passed to FileWriter.write
- copy(atoms=None, name=None, comment=None, copy_atoms=True)#
creates a new copy of the geometry
parameters: :param atoms list(Atom): atoms to copy defaults to all atoms :param name str: defaults to NAME_copy
- parse_comment()#
Saves auxillary data found in comment line
- fix_comment()#
sets self.comment to define key atoms for ligands, etc.
- freeze(targets=None)#
freezes atoms in the geometry
- Parameters:
targets (list(Atom|str|Finder)) – atoms to freeze
- relax(targets=None)#
relaxes atoms in the geometry
- Parameters:
targets (list(Atom|str|Finder)) – atoms to unfreeze
- get_constraints(as_index=True)#
get frozen atoms
- Parameters:
as_index (bool) – return indices instead of atoms
- Returns:
frozen atoms
- Return type:
list(int|Atom)
- get_connectivity()#
list of connectivity for each atom
- get_frag_list(targets=None, max_order=None)#
find fragments connected by only one bond (both fragments contain no overlapping atoms)
- Parameters:
targets – atoms to look for fragments on, defaults to all atoms
max_order (int) – max bond order to cut when defining fragments
- detect_substituents()#
sets self.substituents to a list of substituents
- find(*args, debug=False)#
finds atom in geometry
- Parameters:
args (list|tuple|str|Finder) – tags, names, elements, or a Finder subclass args=([‘this’, ‘that’], ‘other’) will find atoms for which (‘this’ || ‘that’) && ‘other’ == True
Returns:
- Returns:
list of matching atoms
- Return type:
list(Atom)|list()
- Raises:
LookupError – when the tags/names provided do not exist. However, it will return empty list if valid tag/names were provided but were screened out using the && argument form
- find_exact(*args)#
finds exactly the same number of atoms as arguments used. :raises LookupError: if wrong number of atoms found
- refresh_connected(targets=None, threshold=0.3)#
reset connected atoms
atoms are connected if their distance from each other is less than the sum of their covalent radii plus a threshold
- Parameters:
targets – atoms to update connectivity
threshold (float) – upper limit on difference to ideal covalent bond length
- refresh_ranks(invariant=True)#
updates ranks of all atoms
- Parameters:
invariant (bool) – passed to Geometry.canonical_rank
- make_oniom()#
convert existing geometry composed of Atom objects to geometry of OniomAtom objects including changing all atoms in attribute lists to OniomAtom objects
- get_invariants(heavy_only=False)#
returns a list of invariants for the specified targets see Atom.get_invariant for some more details
- canonical_rank(heavy_only=False, break_ties=True, update=True, invariant=True)#
determine canonical ranking for atoms
- Parameters:
invariant (bool) – if True, use invariant described in J. Chem. Inf. Comput. Sci. 1989, 29, 2, 97–101 (DOI: 10.1021/ci00062a008) if False, use neighbor IDs
algorithm described in J. Chem. Inf. Model. 2015, 55, 10, 2111–2120 (DOI: 10.1021/acs.jcim.5b00543)
- element_counts()#
number of each element in this Geometry
- Return type:
dict(str:int)
- reorder(start=None, targets=None, heavy_only=False)#
Depth-first reorder of atoms based on canonical ranking
- Return type:
tuple(list(ordered_targets), list(non_targets))
- detect_fragments(targets, avoid=None)#
Returns a list of Geometries in which the connection to other atoms in the larger geometry must go through the center atoms
for example,
L1--C--L2 ( / L1/
will give two fragments, L1 and L2
- shortest_path(atom1, atom2, avoid=None)#
Uses Dijkstra’s algorithm to find shortest path between atom1 and atom2
- Parameters:
atom1 – starting atom
atom2 – ending atom
avoid – atoms to avoid on the path
- Returns:
atoms on the path from atom1 to atom2, including atom1 and atom2
- Return type:
list(Atom)
- get_monomers()#
returns a list of lists of atoms for each monomer of self in order
- bond(a1, a2)#
takes two atoms and returns the bond vector
- angle(a1, a2, a3=None)#
returns a1-a2-a3 angle
- dihedral(a1, a2, a3, a4)#
measures dihedral angle of a1 and a4 with respect to a2-a3 bond
- COM(targets=None, heavy_only=False, mass_weight=True)#
calculates center of mass of the target atoms returns a vector from the origin to the center of mass
- Parameters:
targets – the atoms to use in calculation, defaults to all
heavy_only (bool) – exclude hydrogens, defaults to False
- RMSD(ref, align=False, heavy_only=False, sort=True, targets=None, ref_targets=None, debug=False, weights=None, ref_weights=None)#
calculates the RMSD between two geometries Returns: rmsd (float)
- Parameters:
ref (Geometry) – the geometry to compare to
align (bool) – if True (default), align self to other; if False, just calculate the RMSD
heavy_only (bool) – only use heavy atoms (default False)
targets – the atoms in self to use in calculation
ref_targets – the atoms in the reference geometry to use
sort (bool) – canonical sorting of atoms before comparing
debug (bool) – returns RMSD and Geometry([ref_targets]), Geometry([targets])
weights (list(float)) – weights to apply to targets
ref_weights (list(float)) – weights to apply to ref_targets
- get_near(ref, dist, by_bond=False, include_ref=False)#
- Returns:
list of atoms within a distance or number of bonds of a reference point, line, plane, atom, or list of atoms
- Parameters:
ref (list) – the point (eg: [0, 0, 0]), line (eg: [‘*’, 0, 0]), plane (eg: [‘*’, ‘*’, 0]), atom, or list of atoms
dist (float) – the distance threshold or number of bonds away threshold, is an inclusive upper bound (uses this <= dist)
by_bond (bool) – if true, dist is interpreted as the number of bonds away instead of distance in angstroms NOTE: by_bond=True means that ref must be an atom or list of atoms
include_ref (bool) – if Atom or list(Atom) given as ref, include these in the returned list, (default=False, do not include ref in returned list)
- get_principle_axes(mass_weight=True, center=None)#
- Parameters:
mass_weight (bool) – mass-weight axes (i.e. moments of inertia)
center (np.ndarray) – center of rotation, defaults to Geometry.COM
- Returns:
[principal moments], [principle axes]
- LJ_energy(other=None, use_prev_params=False)#
computes LJ energy using autodock parameters
- Parameters:
other (Geometry) – calculate LJ energy between self and other instead of just self
use_prev_params (bool) – use same sigma/epsilon as the last time LJ_energy was called; useful for methods that make repetitive LJ_energy calls, like minimize_torsion
- examine_constraints(thresh=None)#
Determines if constrained atoms are too close/ too far apart
- Returns:
(atom1, atom2, flag) where flag is 1 if atoms too close, -1 if atoms to far apart (so one can multiply a distance to change by the flag and it will adjust in the correct direction)
- compare_connectivity(ref, thresh=None, return_idx=False)#
Compares connectivity of self relative to ref
- Parameters:
ref – the structure to compare to (str(path), FileReader, or Geometry) ref.atoms should be in the same order as self.atoms
thresh (float) – allow for connectivity changes as long as the difference between bond distances is below a threshold, default None
return_idx (bool) – output will be indices of atoms instead of names
- Returns:
broken, formed
broken - set of atom name pairs for which a bond broke
formed - set of atom name pairs for which a bond formed
- Return type:
set(), set()
- percent_buried_volume(center=None, targets=None, radius=3.5, radii='umn', scale=1.17, exclude=None, method='lebedev', rpoints=20, apoints=1454, min_iter=25, basis=None, n_threads=1)#
calculates % buried volume (%V_bur) using Monte-Carlo or Gauss-Legendre/Lebedev integration
see Organometallics 2008, 27, 12, 2679–2681 (DOI: 10.1021/om8001119) for details
- Parameters:
center – center atom(s) or np.array of coordinates if more than one atom is specified, the sphere will be centered on the centroid between the atoms
targets – atoms to use in calculation, defaults to all non-center if there is only one center, otherwise all atoms
radius (float) – sphere radius around center atom
radii (str|dict) – “umn” or “bondi”, VDW radii to use can also be a dict() with atom symbols as the keys and their respective radii as the values
scale (float) – scale VDW radii by this
method (str) – integration method (MC or lebedev)
rpoints (int) – number of radial shells for Lebedev integration
apoints (int) – number of angular points for Lebedev integration
min_iter (int) – minimum number of iterations for MC integration each iteration is a batch of 3000 points iterations will continue beyond min_iter if the volume has not converged
basis (np.ndarray) – change of basis matrix will cause %Vbur to be returned as a tuple for different quadrants (I, II, III, IV)
n_threads (int) – number of threads to use for MC integration using multiple threads doesn’t benefit performance very much
- steric_map(center=None, key_atoms=None, targets=None, radii='umn', radius=3.5, oop_vector=None, ip_vector=None, return_basis=False, num_pts=100, shape='circle')#
- Parameters:
center – atom, list of atoms, or array specifiying the origin
key_atoms – list of ligand key atoms. Atoms on these ligands will be in the steric map.
radii (str|dict) – “umn”, “bondi”, or dict() specifying the VDW radii to use
oop_vector (np.ndarray) – None or array specifying the direction out of the plane of the steric map if None, oop_vector is determined using the average vector from the key atoms to the center atom
ip_vector (np.ndarray) – None or array specifying a vector in the plane of the steric map if None, ip_vector is determined as the plane of best fit through the key_atoms and the center
return_basis (bool) – whether or not to return a change of basis matrix
num_pts (int) – number of points along x and y axis to use
shape (str) – “circle” or “square”
- Returns:
x, y, z, min_alt, max_alt
or x, y, z, min_alt, max_alt, basis, atoms if return_basis is True
a contour plot can be created with this data - see stericMap.py command line script
x - x coordinates for grid
y - y coordinates for grid
z - altitude levels; points where no atoms are will be -1000
min_alt - minimum altitude (above -1000)
max_alt - maximum altitute
basis - basis to e.g. reorient structure with np.dot(self.coords, basis)
atoms - list of atoms that are in the steric map
- sterimol(L_axis, start_atom, targets, L_func=None, return_vector=False, radii='bondi', at_L=None, buried=False, max_error=None)#
B1 is determined numerically; B2-B4 depend on B1
B5 and L are analytical (unless L_func is not analytical)
see Verloop, A. and Tipker, J. (1976), Use of linear free energy related and other parameters in the study of fungicidal selectivity. Pestic. Sci., 7: 379-390. (DOI: 10.1002/ps.2780070410)
- Parameters:
return_vector (bool) – returns dict of tuple(vector start, vector end) instead
radii (str|dict|list) –
“bondi” - Bondi vdW radii
”umn” - vdW radii from Mantina, Chamberlin, Valero, Cramer, and Truhlar
dict() - radii are values and elements are keys
list() - list of radii corresponding to targets
L_axis (np.ndarray) – vector defining L-axis
targets – atoms to include in the parameter calculation
L_func (function) –
function to evaluate for getting the L value and vector for each atom takes positional arguments:
- atom:
Atom - atom being checked
- start:
Atom - start_atom
- radius:
vdw radius of atom
- L_axis:
unit vector for L-axis
if L_func is not given, the default is the distance from start_atom to the furthest vdw radius projected onto the L-axis
return_vector – returned dictionary will have tuples of start, end for vectors to represent the parameters in 3D space
at_L (float) –
L value to calculate sterimol parameters at
Useful for Sterimol2Vec
buried (float|bool) –
calculate buried sterimol using the given buried radius (or 5.5 if buried is simply True)
buried and at_L are incompatible
max_error (float) –
max. error in angstroms for B1 higher error can sometimes make the calculation go slightly faster
max_error=None will have an error for B1 of at most (sum of radii tangent to B1 face) * (1 - cos(0.5 degrees))
- Returns:
sterimol parameter values in a dictionary
keys are B1, B2, B3, B4, B5, and L
- update_geometry(structure)#
Replace current coords with those from :structure:
- Parameters:
structure – a file name, atom list, Geometry or np.array() of shape Nx3
- get_all_connected(target)#
- Returns:
list of all elements on the target atom’s monomer
- get_fragment(start, stop=None, as_object=False, copy=False, biggest=False)#
- Parameters:
start – the atoms to start on
stop – the atom(s) to avoid stop=None will try all possibilities and return smallest fragment
as_object (bool) – return as list (default) or Geometry object
copy (bool) – whether or not to copy the atoms before returning the list; copy will automatically fix connectivity information
biggest (bool) – if stop=None, will return biggest possible fragment instead of smallest
- Returns:
[Atoms()] if as_object == False
Geometry() if as_object == True
- remove_fragment(start, avoid=None, add_H=True)#
Removes a fragment of the geometry
- Parameters:
start – the atom of the fragment to be removed that attaches to the rest of the geometry
avoid – the atoms :start: is attached to that should be avoided
add_H (bool) – default is to change :start: to H and update bond lengths, but add_H=False overrides this behaviour
- Returns:
- start:
the removed fragment
- Return type:
list(Atom)
- coord_shift(vector, targets=None)#
shifts the coordinates of the target atoms by a vector parameters: :param np.ndarray vector: the shift vector :param targets: the target atoms to shift (default to all)
- change_distance(a1, a2, dist=None, adjust=False, fix=0, as_group=True)#
For setting/adjusting bond length between atoms
- Parameters:
a1 – the first atom
a2 – the second atom
dist (float) – the distance to change by/to. Default is to set the bond length to that determined by RADII
adjust (bool) – default is to set the bond length to dist, adjust=True indicates the current bond length should be adjusted by dist
fix (int) – default is to move both a1 and a2 by half of dist, fix=1 will move only a2 and fix=2 will move only a1
as_group (bool) – default is to move the fragments connected to a1 and a2 as well, as_group=False will only move the requested atom(s)
- rotate_fragment(start, avoid, angle)#
rotates the all atoms on the ‘start’ side of the start-avoid bond about the bond vector by angle
- rotate(w, angle=None, targets=None, center=None)#
rotates target atoms by an angle about an axis
- Parameters:
w (np.ndarray) – the axis of rotation (doesnt need to be unit vector) or a quaternion (angle not required then)
angle (float) – the angle by which to rotate (in radians)
targets – atoms to rotate (defaults to all)
center – if provided, the atom (or COM of a list) will be centered at the origin before rotation, then shifted back after rotation
- mirror(plane='xy')#
mirror self across a plane plane can be xy, xz, yz or an array for a vector orthogonal to a plane
- invert()#
invert self’s coordinates
- change_angle(a1, a2, a3, angle, radians=True, adjust=False, fix=0, as_group=True)#
For setting/adjusting angle between atoms
- Parameters:
a1 – first atom
a2 – second atom (vertex)
a3 – third atom
angle (float) – the angle to change by/to
radians (bool) – default units are radians, radians=False uses degrees
adjust (bool) – default is to set the angle to angle, adjust=True indicates the current angle should be adjusted by angle
fix (int) – default is to move both a1 and a3 by half of angle, fix=1 will move only a3 and fix=3 will move only a1
as_group (bool) – default is to move the fragments connected to a1 and a3 as well, as_group=False will only move the requested atom(s)
- change_dihedral(*args, **kwargs)#
For setting/adjusting dihedrals
- Parameters:
args –
- a1:
the first atom
- a2:
the second atom
- a3:
the third atom (optional for adjust=True if as_group=True)
- a4:
the fourth atom (optional for adjust=True if as_group=True)
- dihedral:
the dihedral to change by/to
kwargs –
- fix:
default is to move both a1 and a4 by half of dihedral, fix=1 will move only a4 and fix=4 will move only a1
- adjust:
default is to set the dihedral to dihedral, adjust=True indicates the current dihedral should be adjusted by dihedral
- as_group:
default is to move the fragments connected to a1 and a3 as well, as_group=False will only move the requested atom(s)
- radians:
default units are degrees, radians=True to use radians
- minimize_sub_torsion(geom=None, all_frags=False, increment=30, allow_planar=False)#
rotate substituents to try to minimize LJ potential
- Parameters:
geom – calculate LJ potential between self and another geometry-like object, instead of just within self
all_frags (bool) – minimize rotatable bonds on substituents
increment (float) – angle stride in degrees
allow_planar (bool) – allow substituents that start and end with atoms with planar VSEPR geometries that are nearly planar to be rotated
- minimize_torsion(targets, axis, center, geom=None, increment=5)#
Rotate :targets: to minimize the LJ potential
- Parameters:
targets – the target atoms to rotate
axis (np.ndarray) – the axis by which to rotate
center (np.ndarray|Atom) – where to center before rotation
geom (Geometry) – calculate LJ potential between self and another geometry-like object, instead of just within self
increment (float) – angle stride in degrees
- substitute(sub, target, attached_to=None, minimize=False)#
substitutes fragment containing target with substituent sub
- Parameters:
sub (str|Substituent) – substituent (or name from the library) to use
target – atom to place the substituent on
attached_to –
if attached_to is provided, this is the atom where the substituent is attached;
if attached_to=None, replace the smallest fragment containing target
minimize (bool) – rotate sub to lower LJ potential
- find_substituent(start, for_confs=False)#
Finds a substituent based on a given atom (matches start==sub.atoms[0])
- Parameters:
start – the first atom of the subsituent, where it connects to sub.end
for_confs – if true(default), only consider substituents that need to be rotated to generate conformers
- get_substituents(for_confs=True)#
Returns list of all substituents found on all components
- Parameters:
for_confs – if true (default), returns only substituents that need to be rotated to generate conformers
- ring_substitute(targets, ring_fragment, minimize=False, flip_walk=False)#
take ring, reorient it, put it on self and replace targets with atoms on the ring fragment
- Parameters:
targets – pair of atoms to be in the ring
ring_fragment (str|Ring) – Ring or name of ring in the library
minimize (bool) – try other rings with the same name (appended with a number) in the library to see if they fit better
flip_walk (bool) – also flip the rings when minimizing to see if that fits better
- change_element(target, new_element, adjust_bonds=False, adjust_hydrogens=False, hold_steady=None)#
change the element of an atom on self
- Parameters:
target – target atom
new_element (str) – element of new atom
adjust_bonds (bool) – bool adjust distance to bonded atoms
adjust_hydrogens (bool|tuple(int, str)) –
- bool:
try to add or remove hydrogens and guess how many hydrogens to add or remove
- tuple(int, str):
remove specified number of hydrogens and set the geometry to the specified shape (see Atom.get_shape for a list of shapes)
hold_steady – atom bonded to target that will be held steady when adjusting bonds; Default - longest fragment
- map_ligand(ligands, old_keys, minimize=True)#
Maps new ligand according to key_map
- Parameters:
ligand – the name of a ligand in the ligand library
old_keys – the key atoms of the old ligand to map to
minimize (bool) – rotate groups slightly to reduce steric clashing
- remove_clash(sub_list=None)#
rotates substituents slightly to reduce steric clashing
- minimize()#
Rotates substituents in each component to minimize LJ_energy. Different from Component.minimize_sub_torsion() in that it minimizes with respect to the entire catalyst instead of just the component
- next_conformer(conf_spec, skip_spec={})#
Generates the next possible conformer
- Parameters:
conf_spec (dict) – {sub_start_number: conf_number}
skip_spec (dict) – {sub_start_number: [skip_numbers]}
- Returns:
conf_spec if there are still more conformers {} if there are no more conformers to generate
- oniom_layer(layer='', low_layer='', as_object=False)#
returns atoms for the specified layer and adds link atoms
- Parameters:
layer (str) – ONIOM layer (H, M, L)
low_layer (str) – label for low layer, defaults to L
as_object (bool) –
True - return Geometry
False - return list(Atom)
- add_links(high_layer='', low_layer='')#
defines links between ONIOM layers
- make_conformer(conf_spec)#
rotates substituents according to the specified conformer specification
- Parameters:
conf_spec (dict) – {sub_start_number: (conf_number, [skip_numbers])}
- Returns:
conf_spec, True if conformer generated (allowed by conf_spec), conf_spec, False if not allowed or invalid
- get_aromatic_atoms(atoms, return_rings=False, return_h=False)#
- Returns:
List(Atom) of atoms in aromatic rings, including hydrogens if return_h is True
- Charge (int) (also could be number of atoms in aromatic rings not participating in aromaticity) of rings
number of rings (int) that are fused (napthalene would be 2)
List of aromatic rings if return_rings is True
- get_gaff_geom()#
- Returns:
geometry comprised of OniomAtoms with GAFF atomtypes from OfType finder
- define_layer(layer, reference, distance, bond_based=False, expand=True, force=False, res_based=False)#
define an ONIOM layer based on reference information reference can be list(Atom), list(list(float)), list(float), or str representing a layer (H, M, L, !H, etc) if defining a 3 layer job, start at High layer (reaction center)
- change_chirality(target)#
change chirality of the target atom target should be a chiral center that is not a bridgehead of a fused ring, though spiro centers are allowed
- detect_solvent(solvent)#
detects solvent based on either an input xyz, solvent in solvent library, or input SMILES
- update_charges(charges='')#
update the atomic partial charges. accepts Tuple or List(charges), Dict{atom name: charge}
- update_atom_types(atom_types)#
update the molecular mechanics atom types. accepts Tuple or List(atom types), Dict{atom name: atom type}