Atoms & Geometries
easyxtb.Atom
dataclass
An individual atom with an element symbol and 3D coordinates in ångstrom.
Attributes:
-
element(str) –The element's symbol.
-
x(float) –The x-component of the atom's position in ångstrom.
-
y(float) –The y-component of the atom's position in ångstrom.
-
z(float) –The z-component of the atom's position in ångstrom.
easyxtb.Geometry
Geometry(atoms: list[Atom], charge: int = 0, spin: int = 0, _comment: str | None = None)
A set of atoms within a 3D space with an associated overall charge and spin.
Provides class methods for creation from, and instance methods for writing to, the XYZ and CJSON formats.
spin is the number of unpaired electrons, not the multiplicity, matching
the --uhf flag of xtb.
Attributes:
-
atoms(list[Atom]) –The
Atomobjects that collectively comprise theGeometry. -
charge(int) –The overall charge on the
Geometryin terms of elementary charges. -
spin(int) –The number of unpaired electrons.
Source code in easyxtb/geometry.py
easyxtb.Geometry.__iter__
__iter__() -> Iterator[Atom]
Iterate over the constituent atoms.
This allows a Geometry to be iterated over using e.g.
Source code in easyxtb/geometry.py
easyxtb.Geometry.from_cjson
classmethod
Create a Geometry object from a CJSON in the form of a Python dict.
If the CJSON does not specify the overall charge and spin, a neutral singlet is assumed, regardless of the chemical feasibility of that, unless the values are specified as arguments.
Source code in easyxtb/geometry.py
easyxtb.Geometry.from_multi_xyz
classmethod
Create a set of Geometry objects from an XYZ (in the form of a list of
lines) that contains multiple different structures.
All structures must have the same number of atoms, though the order and elements of the atoms must not necessarily be identical.
The number and content of lines between structures is pretty much irrelevant.
Source code in easyxtb/geometry.py
easyxtb.Geometry.from_xyz
classmethod
Create a Geometry object from an XYZ in the form of a list of lines.
Source code in easyxtb/geometry.py
easyxtb.Geometry.load_file
classmethod
load_file(file: PathLike, format: str = None, multi: bool = False, charge: int = None, spin: int = None)
Create a Geometry object from an XYZ or CJSON file.
The format can be specified by passing either ".xyz" or ".cjson" as the
format argument, or it can be left to automatically be detected based on the
filename suffix.
Charge and spin are handled as by the from_xyz() and from_cjson() methods:
- if the file is a CJSON, charge and spin will be read from the file if present,
then will default to 0;
- if the file is an XYZ, they will be assumed to be 0.
In all cases passing them as arguments will override everything.
The method attempts to automatically detect an XYZ file containing multiple
structures, parse as appropriate, and return a list of Geometry objects.
If you know that a file contains multiple structures, or you wish to make sure
that the return value is always a list, even for a single geometry, you can
force this mode by passing multi=True.
Source code in easyxtb/geometry.py
easyxtb.Geometry.to_cjson
Generate a CJSON, as a Python dict, for the geometry.
Source code in easyxtb/geometry.py
easyxtb.Geometry.to_xyz
Generate an XYZ, as a list of lines, for the geometry.
Optional text to include on the second line of the XYZ can be passed as
comment. If left as None, it defaults to "xyz prepared by easyxtb".
Source code in easyxtb/geometry.py
easyxtb.Geometry.write_cjson
Write geometry to a CJSON file at the provided path.
With the default prettyprint option, all simple arrays (not themselves
containing objects/dicts or arrays/lists) will be flattened onto a single line,
while all other array elements and object members will be pretty-printed with
the specified indent level.
indent and any **kwargs are passed to Python's json.dumps() as is, so the
same values are valid e.g. indent=0 will insert newlines while indent=None
will afford a compact single-line representation.
The file is written with a trailing newline.
Returns the location of the saved file for convenience.
Source code in easyxtb/geometry.py
easyxtb.Geometry.write_file
Write geometry to an XYZ or CJSON file.
The format can be specified by passing either ".xyz" or ".cjson" as the format
argument, or it can be left to automatically be detected based on the filename
ending.
Source code in easyxtb/geometry.py
easyxtb.Geometry.write_xyz
Write geometry to an XYZ file at the provided path.
The file is written with a trailing newline.
Returns the location of the saved file for convenience.