tqchem.chem =========== .. py:module:: tqchem.chem Functions --------- .. autoapisummary:: tqchem.chem.is_smiles_string tqchem.chem.is_multiline_string tqchem.chem.is_existing_file tqchem.chem.ase_from_rdkit tqchem.chem.ase_to_rdkit tqchem.chem.ase_from_path tqchem.chem.ase_from_molecule_file_content tqchem.chem.rdkit_from_smiles tqchem.chem.ase_from_smiles tqchem.chem.ase_to_xyz_content tqchem.chem.ase_molecule tqchem.chem.xyz_contents tqchem.chem.align_molecules tqchem.chem.align_xyz_strings tqchem.chem.rdkit_molecules_to_xyz tqchem.chem.adjacencyMatrix tqchem.chem.bondMatrix tqchem.chem.determineBonds tqchem.chem.element_color tqchem.chem.wiberg_bond_orders tqchem.chem.atoms_collided tqchem.chem.adjacency_differs tqchem.chem.generate_rdkit_conformers Module Contents --------------- .. py:function:: is_smiles_string(string: str) -> bool Check if string could be a smiles string SMILES strings may contain: - Letters of the element symbols: - b, c, n, o, p, s for aromatic atoms - Numbers for rings - . - = # $ : / \ for Bonds - [] + - for Atom and charge specification - () for branching - @ for stereocenters .. py:function:: is_multiline_string(string: str) -> bool .. py:function:: is_existing_file(string: str) -> bool Tries to check if a string could be an existing file An OSError is for example raised when the filename is too long. As the error codes are OS dependent we can only assume that an OSError means that we do not have a valid file. .. py:function:: ase_from_rdkit(molecule: rdkit.Chem.Mol, conformer: rdkit.Chem.Conformer | int = -1) -> ase.Atoms Convert rdkit.Mol object to ase.Atoms object Note the Molecule needs to be "embedded" or have 3D coordinates .. py:function:: ase_to_rdkit(molecule: ase.Atoms, charge: int = 0) -> rdkit.Chem.Mol Convert ase.Atoms object to rdkit.Mol object .. py:function:: ase_from_path(path: pathlib.Path, format_: str = None) -> ase.Atoms .. py:function:: ase_from_molecule_file_content(string: str, format_: str = None) -> ase.Atoms Convert a string containing a molecule file's content to ase.Atoms The format could be .xyz, .mol, .sdf, but if none is specified .xyz is assumed .. py:function:: rdkit_from_smiles(smiles: str) -> rdkit.Chem.Mol Convert a smiles string to a rdkit Molecule .. py:function:: ase_from_smiles(smiles: str) -> ase.Atoms Convert a smiles string to ase.Atoms object using rdkit .. py:function:: ase_to_xyz_content(molecule: ase.Atoms, comment: str = '') -> str Return string containing the contents of an xyz file .. py:function:: ase_molecule(input_: pathlib.Path | str | ase.Atoms | rdkit.Chem.Mol, format_: str = None) -> ase.Atoms Smart factory for ase.Atoms object :param input_: Molecule provided as: Path object, ase.Atoms, rdkit.Chem.Mol, or string containing the contents of an xyz file, a Smiles string or a filename :type input_: (Path | str | ase.Atoms | Chem.Mol) :param format_: Optional format string used when a filename or Path or the content of a molecule file are provided :type format_: str, optional :returns: **molecule** :rtype: ase.Atoms .. py:function:: xyz_contents(input_: pathlib.Path | str | ase.Atoms | rdkit.Chem.Mol, comment: str = '') -> str Given a molecule specification return the contents of the corresponding xyz file .. py:function:: align_molecules(molecules: list[rdkit.Chem.Mol], reference: rdkit.Chem.Mol, to_previous: bool = False) -> list[float] Aligns molecules to a reference molecule. :param molecules: list of molecules to align :type molecules: list[rdkit.Chem.Mol] :param reference: Molecule to align to :type reference: rdkit.Chem.Mol :param to_previous: Align to previous molecule :type to_previous: bool, optional :returns: **rmsds** -- list of root mean square deviations from the reference :rtype: list[float] .. py:function:: align_xyz_strings(xyzs: list[str], reference: str, to_previous: bool = False) -> tuple[list[str], list[float]] Aligns molecules to a reference molecule. :param xyzs: list of strings containing xyz data :type xyzs: list[str] :param reference: String containing xyz data for the reference to align against :type reference: str :param to_previous: Align to previous molecule :type to_previous: bool, optional :returns: * **aligned_xyzs** (*list[str]*) -- aligned xyz strings * **rmsds** (*list[float]*) -- list of root mean square deviations from the reference .. py:function:: rdkit_molecules_to_xyz(molecules: list[rdkit.Chem.Mol], path: str | pathlib.Path) -> None Write list of rdkit molecules to xyz file :param molecules: list of molecules to write to file :type molecules: list[rdkit.Chem.Mol] :param path: Path to the xyz file :type path: str | Path .. py:function:: adjacencyMatrix(mol: ase.Atoms) -> numpy.ndarray Determine adjacency matrix based on atomic distances :param mol: Object representing the molecule :type mol: ase.atoms.Atoms :returns: **mat** -- Adjacency matrix for each pair of atoms :rtype: np.array .. py:function:: bondMatrix(mol: ase.Atoms, radius_cutoff: float = ...) Determine bond matrix based on atomic distances :param mol: Object representing the molecule :type mol: ase.atoms.Atoms :param radius_cutoff: Cutoff for the bond length :type radius_cutoff: float :returns: **mat** -- matrix which is 1 for bond between atoms and 0 otherwise :rtype: np.array .. py:function:: determineBonds(mol: ase.Atoms) -> numpy.ndarray Determine the bonds based on the adjacency matrix .. py:function:: element_color(atomic_number: int) -> tuple[float, float, float] Return element color for a given atomic number .. py:function:: wiberg_bond_orders(molecule: ase.Atoms) -> numpy.ndarray .. py:function:: atoms_collided(molecule: ase.Atoms, cutoff: float = 0.5) -> bool True if two atoms are closer than a set cutoff. .. py:function:: adjacency_differs(adjacency1: numpy.ndarray, adjacency2: numpy.ndarray) -> bool Return if 2 adjacency matrices differ .. py:function:: generate_rdkit_conformers(molecule: rdkit.Chem.Mol, n_conformers: int, threshold: float = 0.125, keep_current: bool = False, threads: int = 4, seed: int = 42) -> list[int] Generate conformers from rdkit and returns ids of generated ones The conformers are stored inside the molecule and a list of conformer ids for the conformers generated during this function is returned :param molecule: rdkit molecule object :type molecule: Chem.Mol :param n_conformers: Number of conformers to generate. If threshold > 0 we generate 10 times more to get at least the specified number :type n_conformers: int, :param threshold: RMSD threshold below which we consider conformers identical :type threshold: float, default=0.125 :param keep_current: Keep conformers currently stored in molecule :type keep_current: bool, default=False :param threads: Number of threads to use in the conformer generation :type threads: int, default=4 :param seed: Random seed :type seed: int, default=42 :rtype: list of conformer ids for the conformers generated