MMoleculeObject¶
- class manim_chemistry.twoD.molecule.MMoleculeObject(atoms_dict: dict, bonds_dict: dict, representation_type: str | None = None, explicit_carbons: bool = False, explicit_hydrogens: bool = False, planar: bool = True, add_atoms_numbering: bool = False, add_bonds_numbering: bool = False, rotate_bonds: list = [], **kwargs)[source]¶
Bases:
VGroup
,AbstractMolecule
Represents a molecule in a similar fashion as it is done in academia.
Examples¶
Example: MMoleculeFromFile ¶
from manim import * from manim_chemistry import * class MMoleculeFromFile(Scene): def construct(self): mmolecule = MMoleculeObject.molecule_from_file( "../examples/molecule_files/mol_files/acetone_2d.mol" ) self.wait() self.play(Write(mmolecule)) self.wait()
from manim_chemistry import * class MMoleculeFromFile(Scene): def construct(self): mmolecule = MMoleculeObject.molecule_from_file( "../examples/molecule_files/mol_files/acetone_2d.mol" ) self.wait() self.play(Write(mmolecule)) self.wait()
Example: MMoleculeFromPubChem ¶
from manim import * from manim_chemistry import * class MMoleculeFromPubChem(Scene): def construct(self): mmolecule = MMoleculeObject.molecule_from_pubchem(name="acetone") self.wait() self.play(Write(mmolecule)) self.wait()
from manim_chemistry import * class MMoleculeFromPubChem(Scene): def construct(self): mmolecule = MMoleculeObject.molecule_from_pubchem(name="acetone") self.wait() self.play(Write(mmolecule)) self.wait()
- find_atom_position_by_index(atom_index: int) array [source]¶
_summary_ Returns the position of a single atom given its index.
Example:
` molecule = MMoleculeObject.molecule_from_file("examples/molecule_files/mol_files/dimethylpropane.mol") print(molecule.find_atom_position_by_index(1)) >>> array([ 0.9397, -0.7497, 0. ]) `
- Args:
atom_index (int): Index of the atom inside the VDict.
- Returns:
np.array: Array with the [x, y, z] coordinates of the atom.
- find_atoms_position_by_index(atoms_index_list: list) list [source]¶
_summary_
Returns the position of multiple atoms given their indices.
Example:
` molecule = MMoleculeObject.molecule_from_file("examples/molecule_files/mol_files/dimethylpropane.mol") print(molecule.find_atoms_position_by_index([1,2,3])) >>> [array([ 0.0713, -0.0263, 0. ]), array([-1.2754, 0.3464, 0. ]), array([0.9674, 1.2186, 0. ])] `
Args:atoms_index_list (list): List of atoms indices to be gotten.
- Returns:
list: List of the atoms positions.
- find_bond_center_by_index(bond_index: int) array [source]¶
_summary_
Returns the [x, y, z] coordinates of a bond given a bond index.
Example:
` molecule = MMoleculeObject.molecule_from_file("examples/molecule_files/mol_files/dimethylpropane.mol") print(molecule.find_bond_center_by_index(1)) >>> array([0.51935, 0.59615, 0. ]) `
- Args:
bond_index (int): index of the bond
- Returns:
np.array: [x, y, z] coordinates of bond center.
- find_bonds_center_by_index(bonds_index_list: list) list [source]¶
_summary_
Returns the position of multiple bonds given their indices.
Example:
` molecule = MMoleculeObject.molecule_from_file("examples/molecule_files/mol_files/dimethylpropane.mol") print(molecule.find_bonds_center_by_index([1,2,3])) >>> [array([ 0.0713, -0.0263, 0. ]), array([-1.2754, 0.3464, 0. ]), array([0.9674, 1.2186, 0. ])] `
Args:bondss_index_list (list): List of bonds indices to be gotten.
- Returns:
list: List of the bonds positions.
- find_position_along_bond_axis(bond_index: int, position_buff: float) array [source]¶
_summary_ Returns a position along the bond axis given a bond index and depending on a position_buff. A value of 1 will return one end of the bond. A value of -1 will return the other end. All values in between return positions at some point of the middle of the bond, being 0 the center. Values bigger or lower that 1 and -1 will return positions outside the bond.
- Args:
bond_index (int): Index of the bond position_buff (float): Position buff
- Returns:
np.array: [x, y, z] coordinates of the final position selected.
- classmethod mc_molecule_to_atoms_and_bonds(mc_molecule: MCMolecule) Tuple[Dict, Dict] [source]¶
Transforms the structure of a mc_molecule to a (vertices, edges) tuple with the following structure: - Vertices: {<atom_index>: MCAtom} - Edges: {(<from_atom_index>, <to_atom_index>): MCBond}
- Args:
mc_molecule (MCMolecule): _description_
- Returns:
Tuple[Dict, Dict]: _description_