Molecule

This is the pydoc code for the molecule module.

# molli.chem.molecule This submodule defines the most crucial part of molli: the Molecule class

class molli.chem.molecule.Molecule(other: Structure | Promolecule | Iterable[Atom | Element | str | int] = None, /, n_atoms: int = 0, *, charge: int = None, mult: int = None, name: str = None, coords: ArrayLike = None, atomic_charges: ArrayLike = Ellipsis, **kwds)

Bases: Structure

This is the fundamental class of the Molli package. This class inherits different methods from Promolecule, Connectivity, CartesianGeometry, and Structure.

property atomic_charges: ndarray

The atomic charges of the Molecule in shape (n_atoms,)

Returns:

Returns the atomic charges of the Molecule

Return type:

np.ndarray

Examples

>>> dendrobine = ml.Molecule.load_mol2(ml.files.dendrobine_mol2)
>>> dendrobine.atomic_charges
array([-0.2981,  0.0024, ...
dump_mol2(stream: StringIO) None

Dumps the mol2 block into the output stream

Parameters:

stream (StringIO, optional) – Output stream, by default None

Examples

>>> dendrobine = ml.Molecule.load_mol2(ml.files.dendrobine_mol2)
>>> with open('dendrobine.mol2', 'w') as f:
>>>     dendrobine.dump_mol2(f)
# Produced with molli package
@<TRIPOS>MOLECULE
dendrobine
...
dumps_mol2() str

Dumps the mol2 block as a string

Returns:

The mol2 block

Return type:

str

Examples

>>> dendrobine = ml.Molecule.load_mol2(ml.files.dendrobine_mol2)
>>> dendrobine.dumps_mol2()
# Produced with molli package
@<TRIPOS>MOLECULE
dendrobine
...
add_atom(a: Atom, coord: ArrayLike, charge: float = None) None

Adds atom to Molecule

Parameters:
  • a (Atom) – Atom to add

  • coord (ArrayLike) – Coordinates to add

  • charge (float, optional) – Charge of atom, by default None

Examples

The Molecule class inherits add_atom()
>>> dendrobine = ml.Molecule.load_mol2(ml.files.dendrobine_mol2)
>>> dendrobine.n_atoms
44
>>> new_atom = ml.Atom("C")
>>> dendrobine.add_atom(new_atom, [0,0,0])
>>> dendrobine.n_atoms
45
del_atom(_a: Atom | int | str | Element) None

Deletes an atom from the Molecule

Parameters:

_a (AtomLike) – An atom, index, label, or Element. This will only delete the first instance of the label or Element found

Examples

The Molecule class inherits del_atom()
>>> dendrobine = ml.Molecule.load_mol2(ml.files.dendrobine_mol2)
>>> dendrobine.get_atom(0)
Atom(element=N, isotope=None, label='N', formal_charge=0, formal_spin=0)
>>> dendrobine.del_atom(0)
>>> dendrobine.get_atom(0)
Atom(element=C, isotope=None, label='C', formal_charge=0, formal_spin=0)
molli.chem.molecule.StructureLike = molli.chem.molecule.Molecule | molli.chem.structure.Structure | molli.chem.structure.Substructure

StructureLike can be a Molecule, Structure, or Substructure