The Python interface is built on top of the C interface, using the ctypes standard module.
This interface is contained in the chemfiles
module, and this page list all
the classes and methods in this module.
All logging in chemfiles uses a global maximal logging level, of type
LogLevel
, which can be manipulated using
log_level
and
set_log_level
. The logging output is by
default redirected to the standard error stream, but this can be changed by using the
log_to_stderr
;
log_to_stdout
;
log_to_file
;
log_callback
and
silent
functions.
chemfiles.logging.
LogLevel
¶chemfiles.logging.
log_callback
(callback)¶Use a callback for logging, instead of the built-in logging system.
The callback
function must have the following signature:
def callback(level, message):
...
return None
where level
is a LogLevel
, and message a string containing the log
message.
chemfiles.logging.
log_level
()¶Get current logging level
chemfiles.logging.
log_to_file
(path)¶Write logs to the file at path
, creating it if needed.
chemfiles.logging.
log_to_stderr
()¶Write logs to the standard error stream. This is the default.
chemfiles.logging.
log_to_stdout
()¶Write logs to the standard output stream.
chemfiles.logging.
set_log_level
(level)¶Set the logging level to level
chemfiles.logging.
silent
()¶Remove all logging output
Chemfiles uses exceptions for error handling, and will only throw one of these
exceptions. The ChemfilesException
base class can be used to catch all chemfiles related errors.
chemfiles.errors.
ArgumentError
¶Error in argument type
chemfiles.errors.
CPPException
(status)¶Error in C++ runtime
chemfiles.errors.
ChemfilesException
¶Base class for all Chemfiles exceptions
chemfiles.errors.
NullPointerError
¶Got a NULL pointer from C!
chemfiles.errors.
clear_errors
()¶Clear any error message saved in the library
chemfiles.errors.
last_error
()¶Get the last error from the library
chemfiles.
Trajectory
(path, mode='r', fformat='')¶A Trajectory
is a chemistry file on the hard drive. It is the
main entry point of Chemfiles.
nsteps
()¶Get the number of steps (the number of frames) in a
Trajectory
.
read
()¶Read the next step of the Trajectory
and return the
corresponding Frame
read_step
(step)¶Read a specific step in the Trajectory
and return the
corresponding Frame
.
set_cell
(cell)¶Set the UnitCell
associated with a Trajectory
.
This UnitCell
will be used when reading and writing the
files, replacing any UnitCell
in the frames or files.
set_topology
(topology)¶Set the Topology
associated with a Trajectory
.
This Topology
will be used when reading and writing the
files, replacing any Topology
in the frames or files.
set_topology_file
(filename)¶Set the Topology
associated with a Trajectory
by reading the first Frame
of filename
; and extracting
the Topology
of this Frame
.
sync
()¶Synchronize any buffered content to the hard drive.
write
(frame)¶Write a Frame
to the Trajectory
chemfiles.
Frame
(natoms=0)¶A Frame
holds data from one step of a simulation: the current
Topology
, the positions, and maybe the velocities of the
particles in the system.
guess_topology
(bonds=True)¶Try to guess the bonds, angles and dihedrals in the system. If
bonds
is True, guess everything; else only guess the angles and
dihedrals from the topology bond list.
chemfiles.
CellType
¶Available cell types in Chemfiles:
CellType.Orthorhombic
: The three angles are 90°CellType.Triclinic
: The three angles may not be 90°CellType.Infinite
: Cell type when there is no periodic boundary
conditionschemfiles.
UnitCell
(a, b, c, alpha=90.0, beta=90.0, gamma=90.0)¶An UnitCell
represent the box containing the atoms in the
system, and its periodicity.
A unit cell is fully represented by three lenghts (a, b, c); and three angles (alpha, beta, gamma). The angles are stored in degrees, and the lenghts in Angstroms. A cell also has a matricial representation, by projecting the three base vector into an orthonormal base. We choose to represent such matrix as an upper triangular matrix:
| a_x b_x c_x |
| 0 b_y c_y |
| 0 0 c_z |
An unit cell also have a cell type, represented by the CellType
class.
matrix
()¶Get the unit cell matricial representation.
set_angles
(alpha, beta, gamma)¶Set the three angles of an UnitCell
, in degrees. This is
only possible for CellType.Triclinic
cells.
set_type
(celltype)¶Set the type of the unit cell
type
()¶Get the type of the unit cell
volume
()¶Get the volume of the unit cell
chemfiles.
Topology
¶A Topology
contains the definition of all the particles in the
system, and the liaisons between the particles (bonds, angles, dihedrals,
...).
Only the atoms and the bonds are stored, the angles and the dihedrals are computed automaticaly.
add_bond
(i, j)¶Add a bond between the atoms at indexes i
and j
in the system
angles
()¶Get the list of angles in the system
angles_count
()¶Get the number of angles in the system
bonds
()¶Get the list of bonds in the system
bonds_count
()¶Get the number of bonds in the system
dihedrals
()¶Get the list of dihedral angles in the system
dihedrals_count
()¶Get the number of dihedral angles in the system
isangle
(i, j, k)¶Tell if the atoms at indexes i
, j
and k
constitues an angle
isbond
(i, j)¶Tell if the atoms at indexes i
and j
are bonded together
isdihedral
(i, j, k, m)¶Tell if the atoms at indexes i
, j
, k
and m
constitues a
dihedral angle
remove
(index)¶Remove an Atom
from the Topology
by index. This
can modify all the other atoms indexes.
remove_bond
(i, j)¶Remove any existing bond between the atoms at indexes i
and j
in the system
chemfiles.
AtomType
¶Available types of atoms:
AtomType.Element
: Element from the periodic table of elements
AtomType.CorseGrain
: Corse-grained atom are composed of more than oneelement: CH3 groups, amino-acids are corse-grained atoms.
AtomType.Dummy
: Dummy site, with no physical reality
AtomType.Undefined
: Undefined atom type
chemfiles.
Atom
(name)¶An Atom
is a particle in the current Frame
. It can
be used to store and retrieve informations about a particle, such as mass,
name, atomic number, etc.
atomic_number
()¶Try to get the atomic number of the Atom
. If the number can
not be found, returns -1.
covalent_radius
()¶Try to get the covalent radius of the Atom
. If the radius
can not be found, returns -1.
full_name
()¶Try to get the full name of the Atom
. The full name of “He”
is “Helium”, and so on. If the name can not be found, returns the empty
string.
set_type
(atomtype)¶Set the type of the atom
type
()¶Get the type of the atom
chemfiles.
Selection
(selection)¶Select atoms in a Frame
with a selection language.
The selection language is built by combining basic operations. Each basic
operation follows the <selector>[(<variable>)] <operator> <value>
structure, where <operator>
is a comparison operator in
== != < <= > >=
. Refer to the full documentation to know the allowed selectors and how to use them.