chemcoord.Cartesian

class chemcoord.Cartesian(frame, metadata=None, _metadata=None)[source]

The main class for dealing with cartesian Coordinates.

Mathematical Operations:

It supports binary operators in the logic of the scipy stack, but you need python3.x for using the matrix multiplication operator @.

The general rule is that mathematical operations using the binary operators + - * / @ and the unary operators + - abs are only applied to the ['x', 'y', 'z'] columns.

Addition/Subtraction/Multiplication/Division: If you add a scalar to a Cartesian it is added elementwise onto the ['x', 'y', 'z'] columns. If you add a 3-dimensional vector, list, tuple… the first element of this vector is added elementwise to the 'x' column of the Cartesian instance and so on. The last possibility is to add a matrix with shape=(len(Cartesian), 3) which is again added elementwise. The same rules are true for subtraction, division and multiplication.

Matrixmultiplication: Only leftsided multiplication with a matrix of shape=(n, 3), where n is a natural number, is supported. The usual usecase is for example np.diag([1, 1, -1]) @ cartesian_instance to mirror on the x-y plane.

Indexing:

The indexing behaves like Indexing and Selecting data in Pandas. You can slice with loc(), iloc() and Cartesian[...]. The only question is about the return type. If the information in the columns is enough to draw a molecule, an instance of the own class (e.g. Cartesian) is returned. If the information in the columns is not enough to draw a molecule, there are two cases to consider:

  • A Series instance is returned for one dimensional slices.

  • A DataFrame instance is returned in all other cases.

This means that:

molecule.loc[:, ['atom', 'x', 'y', 'z']] returns a Cartesian.

molecule.loc[:, ['atom', 'x']] returns a pandas.DataFrame.

molecule.loc[:, 'atom'] returns a pandas.Series.

Comparison:

Comparison for equality with == is supported. It behaves exactly like the equality comparison of DataFrames in pandas. Amongst other things this means that the index has to be the same and the comparison of floating point numbers is exact and not numerical. For this reason you rarely want to use ==. Usually the question is “are two given molecules chemically the same”. For this comparison you have to use the function allclose(), which moves to the barycenter, aligns along the principal axes of inertia and compares numerically.

Constructors

__init__(frame[, metadata, _metadata])

from_ase_atoms(atoms)

Create an instance of the own class from an ase molecule

from_pymatgen_molecule(molecule)

Create an instance of the own class from a pymatgen molecule

from_pyscf(mol)

Create an instance of the own class from a PySCF molecule

read_cjson(buf)

Read a cjson file or a dictionary.

read_xyz(buf[, start_index, nrows, engine])

Read a file of coordinate information.

copy()

Export and IO

to_cjson([buf])

Write a cjson file or return dictionary.

to_latex([buf, columns, col_space, header, ...])

Render a DataFrame to a tabular environment table.

to_pyscf(**kwargs)

Convert to a PySCF molecule.

to_string([buf, columns, col_space, header, ...])

Render a DataFrame to a console-friendly tabular output.

to_xyz([buf, sort_index, index, header, ...])

Write xyz-file

write_xyz(*args, **kwargs)

Deprecated, use to_xyz()

view([viewer, use_curr_dir])

View your molecule.

Methods

add_data([new_cols])

Add a column with the requested data.

align(other[, mass_weight])

Align two Cartesians.

basistransform(new_basis[, old_basis, ...])

Transform the frame to a new basis.

change_numbering(rename_dict[, inplace])

Return the reindexed version of Cartesian.

check_absolute_refs(construction_table)

Checks first three rows of construction_table for linear references.

check_dihedral(construction_table)

Checks if the dihedral defining atom is colinear.

correct_absolute_refs(construction_table)

Reindex construction_table if linear reference in first three rows is present.

correct_dihedral(construction_table[, bond_dict])

Reindex the dihedral defining atom if a linear reference is used.

cut_cuboid([a, b, c, origin, ...])

Cut a cuboid specified by edge and radius.

cut_sphere([radius, origin, outside_sliced, ...])

Cut a sphere specified by origin and radius.

fragmentate([give_only_index, bond_dict])

Get the indices of non bonded parts in the molecule.

get_align_transf(other[, mass_weight, centered])

Return the rotation matrix that aligns other onto self.

get_angle_degrees(indices)

Return the angles between given atoms.

get_ase_atoms()

Create an Atoms instance of the ase library

get_asymmetric_unit([eq])

get_barycenter()

Return the mass weighted average location.

get_bond_lengths(indices)

Return the distances between given atoms.

get_bonds(*[, self_bonding_allowed, offset, ...])

Return a dictionary representing the bonds.

get_centroid()

Return the average location.

get_construction_table([fragment_list, ...])

Create a construction table for a Zmatrix.

get_coordination_sphere(index_of_atom, *[, ...])

Return a Cartesian of atoms in the n-th coordination sphere.

get_dihedral_degrees(indices[, start_row])

Return the dihedrals between given atoms.

get_distance_to([origin, other_atoms, sort])

Return a Cartesian with a column for the distance from origin.

get_electron_number([charge])

Return the number of electrons.

get_equivalent_atoms([tolerance])

Returns sets of equivalent atoms with symmetry operations

get_fragment(list_of_indextuples[, ...])

Get the indices of the atoms in a fragment.

get_grad_zmat(construction_table[, as_function])

Return the gradient for the transformation to a Zmatrix.

get_inertia()

Calculate the inertia tensor and transforms along rotation axes.

get_pointgroup([tolerance])

Returns a PointGroup object for the molecule.

get_pymatgen_molecule()

Create a Molecule instance of the pymatgen library

get_shortest_distance(other)

Calculate the shortest distance between self and other

get_total_mass()

Return the total mass in g/mol.

get_without(fragments[, bond_dict])

Return self without the specified fragments.

get_zmat([construction_table, bond_dict])

Transform to internal coordinates.

has_same_sumformula(other)

Determine if other has the same sum formula.

insert(loc, column, value[, ...])

Insert column into molecule at specified location.

partition_chem_env([n_sphere, bond_dict])

This function partitions the molecule into subsets of the same chemical environment.

reindex_similar(other[, n_sphere])

Reindex other to be similarly indexed as self.

replace([to_replace, value, inplace, limit, ...])

Replace values given in 'to_replace' with 'value'.

reset_index()

Resets the index to 0...n

restrict_bond_dict(bond_dict)

Restrict a bond dictionary to self.

set_atom_coords(atoms, coords[, index])

set_index(keys[, drop, append, inplace, ...])

Set the DataFrame index (row labels) using one or more existing columns.

sort_index([axis, level, ascending, ...])

Sort object by labels (along an axis)

sort_values(by[, axis, ascending, inplace, ...])

Sort by the values along either axis

subs(*args)

Substitute a symbolic expression in ['x', 'y', 'z']

symmetrize([max_n, tolerance, epsilon])

Returns a symmetrized molecule

to_zmat(*args, **kwargs)

Deprecated, use get_zmat().

assign(idx, col, val)

Return a copy where the value is assigned.

Attributes

columns

Returns the columns.

dtypes

iloc

Label based indexing

index

Returns the index.

loc

Label based indexing

shape

Parameters: