Molecule Classes#

Molsys#

class optking.molsys.Molsys(fragments, dimer_intcos=None)[source]#
Bmat(massWeight=False)[source]#

Computes Wilson B Matrix for the moleclar system

Gmat(massWeight=False)[source]#

Calculates BuB^T (calculates B matrix)

Parameters:

masses (List, optional)

property all_fragments#

List of real (“true” moleules) and psuedo (reference atoms) fragments

atom2frag_index(atom_index)[source]#

For a given atom in the overall molecular system return index of the fragment containing that atom

atom_list2unique_frag_list(atomList)[source]#

Given a list of atoms, return all the fragments to which they belong

augment_connectivity_to_single_fragment(C)[source]#

Take the current connectivity and add elements until a walk can be performed between any two atoms

Parameters:

C (np.ndarray) – A previously determined connectivity

Returns:

scale_dist – The scalar of covalent radii required to achieve full connectivity

Return type:

float

constraint_matrix(fq)[source]#

Returns constraint matrix with 1 on diagonal for frozen coordinates. This method used to check for forces being passed in but wasn’t being used. Forces now need to be passed in

Parameters:

fq (np.ndarray forces)

property dimer_intcos: List[DimerFrag]#

Getter for intrafragment intcos from DimerFrag

property dimer_psuedo_frags: List[Frag]#

List of fragments containing the reference atoms utilized in the interfragment coords

fix_bend_axes()[source]#

See description in Fragment class.

frag_1st_atom(iF) int[source]#

Return overall index of first atom in fragment iF, beginning 0,1,… For last fragment returns one past the end.

frag_1st_intco(iF)[source]#

returns the index of the first internal coordinate belonging to fragment

frag_atom_range(iF)[source]#

Gets range for first and last atom indices for a given fragment

frag_atom_slice(iF)[source]#

Same as frag_atom_range() but returns slice

frag_geom(iF)[source]#

cartesian geometry for fragment i

frag_intco_range(iF)[source]#

range of internal coordinates within the overall set corresponding to a given Frag

frag_intco_slice(iF)[source]#

slice of internal coordinates within the overall set corresponding to a given Frag

property frag_natoms: List[int]#

Compute number of atoms for each fragment.

Return type:

List[int]

property fragments: List[Frag]#

Getter for list of fragments

static from_psi4(mol, dtype) Tuple[Molsys, dict][source]#

Creates a optking molecular system from psi4 mol. Note that not all information is preserved. :param mol: psi4 mol :type mol: (psi4.core.Molecule, psi4.qcdb.Molecule) :param dtype: QCSchema version. Note that Molecule.schema_version is advanced by 1.

Returns:

  • Molsys – optking molecular system: list of fragments

  • dict – qcschema representation of molecule.

classmethod from_schema(qc_molecule: dict) Molsys[source]#

Creates optking molecular system from JSON input.

Parameters:

qc_molecule (dict) – molecule key in MOLSSI QCSchema see http://molssi-qc-schema.readthedocs.io/en/latest/auto_topology.html

Returns:

molsys cls consists of list of Frags

Return type:

cls

property frozen_intco_list#

Determine vector with 1 for any frozen internal coordinate

property geom#

cartesian geometry [a0]

gradient_to_cartesians(g_q)[source]#

converts the gradient from internal into Cartesian coordinates

Parameters:

g_q (ndarray) – internal coordinate gradient

Returns:

g_x – Cartesian coordinate gradient

Return type:

ndarray

gradient_to_internals(g_x, coeff=1.0, B=None, use_masses=False, threshold=1e-10)[source]#

Transform cartesian gradient to internals :param g_x: (3nat, 1) cartesian gradient :type g_x: np.ndarray :param coeff: prefactor coefficient; -1 for forces :type coeff: float :param B: B matrix to use :type B: np.ndarray, optional :param use_masses: instead of identity, use u = 1/masses in transformation :type use_masses: boolean

Returns:

gradient in internal coordinates (coeff==1)

Return type:

ndarray

Notes

g_q = (BuB^T)^(-1)*B*g_x

hessian_to_internals(H, g_x=None, use_masses=False)[source]#

converts the hessian from cartesian coordinates into internal coordinates Hq = A^t (Hxy - Kxy) A, where K_xy = sum_q ( grad_q[I] d^2(q_I)/(dx dy) and A = (BuB^t)^-1 Bu

Parameters:
  • H (np.ndarray) – Hessian in cartesians

  • g_x (np.ndarray) – (nat, 3) gradient in cartesians (optional)

  • massWeight (boolean) – whether to keep arbitrary transformation matrix u=I or use 1/mass_i as in spectroscopy or cases where rotations/translations matter.

Returns:

Hq – hessian in internal coordinates

Return type:

np.ndarray

property masses#

array of masses for all atoms

property natom: int#

Computes the number of atoms in the molecular system

property nfragments: int#

Get the number of fragments in the molecular system

property num_intcos: int#

Computes total number of internal coordinates (either true internals or number of cartesians) depending on opt_coordinates

property num_intrafrag_intcos#

Computes number of internal coordinates but does not include coordinates in pseudo fragments

print_geom()[source]#

Returns a string of the geometry for logging in [a0]

project_redundancies_and_constraints(fq, H, threshold=1e-08)[source]#

Project redundancies and constraints out of forces and Hessian

q()[source]#

Returns internal coordinate values in au as list.

q_array()[source]#

Returns internal coordinate values in au as array.

q_show()[source]#

returns internal coordinates values in Angstroms/degrees as list.

q_show_array()[source]#

returns internal coordinates values in Angstroms/degrees as array.

q_show_forces(forces)[source]#

Returns scaled forces as array.

ranged_frozen_intco_list(fq)[source]#

Determine vector with 1 for any ranged intco that is at its limit

show_geom()[source]#

Return a string of the geometry in [A]

split_fragments_by_connectivity(covalent_connect=1.3)[source]#

Split any fragment not connected by bond connectivity.

test_Bmat()[source]#

Test the analytic B matrix (dq/dx) via finite differences. The 5-point formula should be good to DISP_SIZE^4 - a few unfortunates will be slightly worse.

Returns:

passes – Returns True or False, doesn’t raise exceptions

Return type:

boolean

test_derivative_Bmat(print_lvl=1)[source]#

Test the analytic derivative B matrix (d2q/dx2) via finite differences. The 5-point formula should be good to DISP_SIZE^4 - a few unfortunates will be slightly worse.

Returns:

passes – Returns True or False, doesn’t raise exceptions

Return type:

boolean

unfix_bend_axes()[source]#

See description in Fragment class.

update_dihedral_orientations()[source]#

See description in Fragment class.

Frag#

class optking.frag.Frag(Z, geom, masses, intcos=None, frozen=False)[source]#
Bmat()[source]#

Computes Wilson B matrix for the fragment

property Z#

Getter for atomic numbers of all atoms in fragment

add_auxiliary_bonds(connectivity=None)[source]#

Add additional bends based on increased covalent radii threshold

add_cartesian_intcos()[source]#

Add cartesian coordinates to “internal” coordinate set.

add_h_bonds()[source]#

Prepend h_bonds because that’s where c++ optking places them

add_intcos_from_connectivity(connectivity=None, ignore_coords=[])[source]#

Automatically add a set of internal coordinates to the fragment based on connectivity

connectivity_from_distances(covalent_connect=1.3)[source]#

Determine the connectivity of the fragment based on covalent radii and distance matrix

fix_bend_axes()[source]#

Makes sure axis defining bends does not change for all Bend intstances in Frag’s intcos

freeze()[source]#

Freezes all internal coordinates in the fragment

property frozen#

Is fragment frozen?

property geom#

Getter for geometry (stored in [au])

property intcos#

Getter for internal coordinates describing geometry of fragment

is_linear()[source]#

Is the fragment a linear molecule

property masses#

Getter for masses of all atoms in fragment [au]

property natom#

number of atoms in frag

property num_intcos#

Getter for number of internal coordinates in fragment

print_intcos()[source]#

Logs a table of current values of internal coordinates in both au and angstroms

q()[source]#

Values of internal coordinates in BOHR/RAD

q_array()[source]#

Array of values of internal coordinates in BOHR/RAD

q_show()[source]#

Values of internal coordinates in ANG/DEG

q_show_array()[source]#

Array of values of internal coordinates in ANG/DEG

unfix_bend_axes()[source]#

Remove constraint on bend axis for all Bend instances in Frag’s intcos

update_dihedral_orientations()[source]#

Update orientation of each dihedrals/tors coordinate This saves an indicator if dihedral is slightly less than pi, or slighly more than -pi. Subsequently, computation of values can be greater than pi or less than -pi to enable computation of Delta(q) when q passed through pi.

DimerFrag#

class optking.dimerfrag.DimerFrag(A_idx, A_atoms, B_idx, B_atoms, A_weights=None, B_weights=None, A_lbl='A', B_lbl='B', frozen=None)[source]#

Set of (up to 6) coordinates between two distinct fragments.

The fragments ‘A’ and ‘B’ have up to 3 reference atoms each (dA[3] and dB[3]). The reference atoms are defined in one of two ways.

  1. If interfrag_mode == FIXED, then fixed, linear combinations of atoms in A and B are used.

  2. If interfrag_mode == PRINCIPAL_AXES (NOT YET IMPLEMENTED), then the references points are
    1. the center of mass

    2. a point a unit distance along the principal axis corresponding to the largest moment.

    3. a point a unit distance along the principal axis corresponding to the 2nd largest moment.

Notes

For simplicity, we sort the atoms in the reference point structure according to the assumed connectivity of the coordinates.

  1. ref_geom[0] = dA[2]

  2. ref_geom[1] = dA[1]

  3. ref_geom[2] = dA[0]

  4. ref_geom[3] = dB[0]

  5. ref_geom[4] = dB[1]

  6. ref_geom[5] = dB[2]

The six coordinates, if present, formed from the d{A-B}{0-2} sets are assumed to be the following in this canonical order:

pos

sym

type

atom-definition

present, if

0

RAB

distance

dA[0]-dB[0]

always

1

theta_A

angle

dA[1]-dA[0]-dB[0]

A has > 1 atom

2

theta_B

angle

dA[0]-dB[0]-dB[1]

B has > 1 atom

3

tau

dihedral

dA[1]-dA[0]-dB[0]-dB[1]

A and B have > 1 atom

4

phi_A

dihedral

dA[2]-dA[1]-dA[0]-dB[0]

A has > 2 atoms and is not linear

5

phi_B

dihedral

dA[0]-dB[0]-dB[1]-dB[2]

B has > 2 atoms and is not linear

Parameters:
  • A_idx (int) – index of fragment in molecule list

  • A_atoms (list of (up to 3) lists of ints) – index of atoms used to define each reference point on A

  • B_idx (int) – index of fragment in molecule list

  • B_atoms (list of (up to 3) lists of ints) – index of atoms used to define each reference point on B

  • (optional) (B_weights) – weights of atoms used to define each reference point of A

  • (optional) – weights of atoms used to define each reference point of B

  • A_lbl (string) – name for fragment A

  • B_lbl (string) – name for fragment B

  • confusing (The arguments are potentially)

  • checking. (so we'll do a lot of)

Bmat(A_geom, B_geom, Bmat_in, A_xyz_off=None, B_xyz_off=None)[source]#

This function adds interfragment rows into an existing B matrix. B is (internals, Cartesians). Often, \(6 x 3*(Natoms)\).

Parameters:
  • A_geom (numpy array) – geometry of fragment A, array is (A atoms,3)

  • B_geom (numpy array that is (B atoms,3)) – geometry of fragment B, array is (B atoms,3)

  • Bmat_int (numpy array) – provided B matrix

  • intco_off (int) – index of first row of Bmatrix to start writing the interfragment rows.

  • A_off (int) – Column of B matrix at which the cartesian coordinates of atoms in fragment A begin. Needed since columns may span full molecular system.

  • B_off (int) – Column of B matrix at which the cartesian coordinates of atoms in fragment B begin.

Notes

If A_off and B_off are not given, then the minimal (dimer-only) B-matrix is returned.

classmethod from_user_dict(user_dict)[source]#

Create instance of DimerFrag from dictionary.

Parameters:

user_dict (dict) – Dictionary representation of dimerfragment coordinates. Required keys: NATOMS PER FRAG, A_REF_ATOMS, and B_REF_ATOMS

Raises:

ValidationError – If user_dict does not adhere to InterfragCoords Schema

orient_fragment(Ageom_in, Bgeom_in, q_target_in, printCoords=False, unit_length='bohr', unit_angle='rad')[source]#
orient_fragment() moves the geometry of fragment B so that the

interfragment coordinates have the given values

Parameters:
  • Ageom_in (array) – Cartesian geometry of fragment A

  • Bgeom_in (array) – Cartesian geometry of fragment B

  • q_target (array float[6]) – Target values of 6 interfragment coordinates after moving fragment B

  • printCoords (boolean) – whether to print the starting and final values of the q’s

  • unit_length (string ; default 'bohr') – indicate unit of length, q[0]

  • unit_angle (string ; default 'rad') – indicate unit of angles, q[1-5]

  • ------------

Returns:

new Cartesian geometry for B

Return type:

array