chemcoord.Cartesian
- class chemcoord.Cartesian(frame=None, atoms=None, coords=None, index=None, 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 withshape=(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)
, wheren
is a natural number, is supported. The usual usecase is for examplenp.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()
andCartesian[...]
. 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:This means that:
molecule.loc[:, ['atom', 'x', 'y', 'z']]
returns aCartesian
.molecule.loc[:, ['atom', 'x']]
returns apandas.DataFrame
.molecule.loc[:, 'atom']
returns apandas.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 functionallclose()
, which moves to the barycenter, aligns along the principal axes of inertia and compares numerically.- __init__(frame=None, atoms=None, coords=None, index=None, metadata=None, _metadata=None)
How to initialize a Cartesian instance.
- Parameters:
frame (pd.DataFrame) – A Dataframe with at least the columns
['atom', 'x', 'y', 'z']
. Where'atom'
is a string for the elementsymbol.atoms (sequence) – A list of strings. (Elementsymbols)
coords (sequence) – A
n_atoms * 3
array containg the positions of the atoms. Note that atoms and coords are mutually exclusive to frame. Besides atoms and coords have to be both either None or not None.
- Returns:
A new cartesian instance.
- Return type:
Methods
__init__
([frame, atoms, coords, index, ...])How to initialize a Cartesian instance.
add_data
([new_cols])Adds a column with the requested data.
align
(other[, mass_weight])Align two Cartesians.
apply
(*args, **kwargs)Applies function along input axis of DataFrame.
applymap
(*args, **kwargs)Applies function elementwise
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 referencescheck_dihedral
(construction_table)Checks, if the dihedral defining atom is colinear.
copy
()correct_absolute_refs
(construction_table)Reindexe construction_table if linear reference in first three rows present.
correct_dihedral
(construction_table[, ...])Reindexe the dihedral defining atom if 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, use_lookup])Get the indices of non bonded parts in the molecule.
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
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.
Create an Atoms instance of the ase library
get_asymmetric_unit
([eq])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.
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.
Calculate the inertia tensor and transforms along rotation axes.
get_pointgroup
([tolerance])Returns a PointGroup object for the molecule.
Create a Molecule instance of the pymatgen library
get_shortest_distance
(other)Calculate the shortest distance between self and other
Returns the total mass in g/mol.
get_without
(fragments[, use_lookup])Return self without the specified fragments.
get_zmat
([construction_table, use_lookup])Transform to internal coordinates.
has_same_sumformula
(other)Determines if
other
has the same sumformulainsert
(loc, column, value[, ...])Insert column into molecule at specified location.
partition_chem_env
([n_sphere, use_lookup])This function partitions the molecule into subsets of the same chemical environment.
read_cjson
(buf)Read a cjson file or a dictionary.
read_xyz
(buf[, start_index, get_bonds, ...])Read a file of coordinate information.
reindex_similar
(other[, n_sphere])Reindex
other
to be similarly indexed asself
.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_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_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_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
to_zmat
(*args, **kwargs)Deprecated, use
get_zmat()
view
([viewer, use_curr_dir])View your molecule.
write_xyz
(*args, **kwargs)Deprecated, use
to_xyz()
Attributes
Returns the columns.
dtypes
empty
Label based indexing
Returns the index.
Label based indexing
shape