conversions

This module enables conversion between MDMC Structure objects and ASE Atom and Atoms objects.

class MDMC.MD.ase.conversions.ASEAtoms(*args, **kwargs)[source]

A subclass of ase.atoms.Atoms with explicit bonds defined between atoms

bonds

An array of tuple, where each tuple is an atom pair, which are specified by the indexes (int) of each atom.

Type

numpy.ndarray

Raises

ValueError – If there are not the same number of ID as there are atoms

write(filename: str, format: str = None, **kwargs: dict) None[source]

Override ase.atoms.Atoms.write so that writing to X3D uses custom X3D class

Parameters
  • filename (str) – The name of the file to which the ASEAtoms object is written

  • format (str) – The name of the format of the file

  • **kwargs – keyword arguments which are passed to the object which performs the writing

class MDMC.MD.ase.conversions.X3D(atoms: ase.atoms.Atoms)[source]

Class to write X3D or X3DOM (html) which can be read by web browers

This is used for inline IPython (Jupyter) visualisation with X3DOM. It overrides the write method of the base class, in order to display bonds as defined within MDMC.

Parameters

atoms (ase.atoms.Atoms) – The ase.atoms.Atoms object to write

atom_lines(atom: ase.atom.Atom) list[source]

Generates a segment of X3D lines representing an atom

Parameters

atom (ase.atom.Atom) – The ase.atom.Atom for which the X3D html will be generated

Returns

A list of (indent, str) pairs for each line requied to describe the atom

Return type

list

bond_lines(bond: tuple) list[source]

Generates a cylinder representing a bond

Parameters

bond (tuple) – A tuple containing the atom indexes for the bond for which the X3D html will be generated

Returns

A list of (indent, str) pairs for each line requied to describe the bond

Return type

list

get_center_of_rotation() numpy.ndarray[source]

Get the center of rotation for the viewpoint

Returns

The center of atoms.cell if this has been set, or the center of the extents of atoms.positions

Return type

numpy.ndarray

get_viewpoint_z() float[source]

Get the z position of the viewpoint which will display all of the atoms

Returns

The z position of the viewpoint

Return type

float

write(fileobj: str, datatype: str = 'X3DOM')[source]

Writes output to an ‘X3DOM’ (html) or ‘X3D’ file

Parameters
  • fileobj (str or file-like) – The file name to which the atoms are written

  • datatype (str, optional) – The output format, which can be ‘X3D’ or ‘X3DOM’ (html). If None, format will be determined from the filename

MDMC.MD.ase.conversions.convert_bond(bond: MDMC.MD.interactions.Bond, index_conv: dict = None) numpy.ndarray[source]

Converts Bond objects into the form required by the ASE GUI

Parameters
  • bond (Bond) – The bond which will be converted.

  • index_conv (dict) – A dictionary of MDMC_ID: ASE_index pairs, where MDMC_ID is an int specifying an Atom.ID, and ASE_index is the corresponding ase.atom.Atom.index. The default is None, which means that the ID and index will be assumed to be identical.

Returns

An array of 2 element list where each element is the int index of an atom between which the bond exists.

Return type

numpy.ndarray

MDMC.MD.ase.conversions.convert_bonds(bonds: list[MDMC.MD.interactions.Bond], index_conv: dict = None) numpy.ndarray[source]

Converts Bond objects into the form required by the ASE GUI

Parameters
  • bonds (list) – The list of Bond objects to be converted

  • index_conv (dict) – A dict of MDMC_ID: ASE_index pairs, where MDMC_ID is an int specifying an Atom.ID, and ASE_index is the corresponding ase.atom.Atom.index. The default is None, which means that the ID and index will be assumed to be identical.

Returns

An array of 2 element list where each element is the int index of an atom between which the bond exists.

Return type

numpy.ndarray

MDMC.MD.ase.conversions.convert_from_ase_atom(ase_atom: MDMC.MD.ase.conversions.ASEAtoms, atom_type: int = None, name: str = None, set_charge: bool = True, cutoff: float = None) MDMC.MD.structures.Atom[source]

Converts an ase.atom.Atom to an MDMC Atom.

As MDMC automatically generates atom ID, ase_atom.index is not passed when initializing an Atom.

Parameters
  • ase_atom (ASEAtom) – An ASEAtom object to be converted to an MDMC Atom object

  • atom_type (int) – The atom_type of the MDMC Atom object.

  • name (str, optional) – A name for the MDMC Atom. The default is the element symbol.

  • set_charge (bool, optional) – Whether the charge is set to the charge of the ase.atom.Atom, or left unset. All ``ase.atom.Atom objects have a charge, which is set to 0. if it is uninitialized. As MDMC Atom objects can have charge=None`, in some cases it might be preferential to leave the ``charge unset. The default is to set the charge.

  • cutoff (float, optional) – The cutoff value for the atom’s charge interaction. Must be set if set_charge is True.

Returns

An MDMC Atom object which is equivalent to ase_atom

Return type

Atom

MDMC.MD.ase.conversions.convert_to_ase_atom(atom: MDMC.MD.structures.Atom, index: int = None) ase.atom.Atom[source]

Converts an MDMC Atom to an ase.atom.Atom

Parameters
  • atom (Atom) – An MDMC Atom object to be converted to an ase.atom.Atom object

  • index (int, optional) – The index of the ase.atom.Atom object which is created. If this is not set, the MDMC Atom.ID is used.

Returns

An ASE.atom.Atom object which is equivalent to atom

Return type

ase.atom.Atom

MDMC.MD.ase.conversions.get_ase_atoms(atoms: Iterable, cell: numpy.ndarray = None) MDMC.MD.ase.conversions.ASEAtoms[source]

Gets an ASEAtoms object equivalent to atoms, including the bonding

Parameters
  • atoms (iterable) – An iterable of MDMC Atom objects to be converted to an ASEAtoms object

  • cell (numpy.ndarray, optional) – A 3 element array specifying the unit cell of the ASEAtoms object. The default is None.

Returns

An ASEAtoms object which is equivalent to atoms

Return type

ASEAtoms