예제 #1
0
    def _get_neighbor_coeffs(self, mol: Molecule) -> Counter:
        """
        Get a counter containing the coefficients for the gamma
        (bond_corr_neighbor) variables.

        Args:
            mol: RMG-Py molecule.

        Returns:
            Counter containing gamma coefficients.
        """
        if hasattr(mol, 'id') and mol.id is not None:
            if mol.id in self._gamma_coeffs:
                return self._gamma_coeffs[mol.id]

        coeffs = Counter()

        for bond in mol.get_all_edges():
            atom1 = bond.atom1
            atom2 = bond.atom2

            # Atoms adjacent to atom1
            counts1 = Counter(a.element.symbol for a, b in atom1.bonds.items() if b is not bond)
            counts1[atom1.element.symbol] += max(0, len(atom1.bonds) - 1)

            # Atoms adjacent to atom2
            counts2 = Counter(a.element.symbol for a, b in atom2.bonds.items() if b is not bond)
            counts2[atom2.element.symbol] += max(0, len(atom2.bonds) - 1)

            coeffs += counts1 + counts2

        if hasattr(mol, 'id'):
            self._gamma_coeffs[mol.id] = coeffs
        return coeffs
예제 #2
0
    def _get_length_coeffs(self, mol: Molecule) -> defaultdict:
        """
        Get a dictionary containing the coefficients for the beta
        (bond_corr_length) variables. There is one coefficient per atom
        type and an additional coefficient for each combination of atom
        types.

        Example: If the atoms are H, C, and O, there are (at most)
        coefficients for H, C, O, (C, H), (H, O), and (C, O).

        Args:
            mol: RMG-Py molecule.

        Returns:
            Defaultdict containing beta coefficients.
        """
        if hasattr(mol, 'id') and mol.id is not None:
            if mol.id in self._beta_coeffs:
                return self._beta_coeffs[mol.id]

        coeffs = defaultdict(float)

        for bond in mol.get_all_edges():
            atom1 = bond.atom1
            atom2 = bond.atom2
            symbol1 = atom1.element.symbol
            symbol2 = atom2.element.symbol

            c = np.exp(-self.exp_coeff * np.linalg.norm(atom1.coords - atom2.coords))
            k = symbol1 if symbol1 == symbol2 else tuple(sorted([symbol1, symbol2]))
            coeffs[k] += c

        if hasattr(mol, 'id'):
            self._beta_coeffs[mol.id] = coeffs
        return coeffs
예제 #3
0
 def test_molecule(self):
     """
     Test that a Molecule contains the `id` attribute.
     """
     rmg_mol = RMGMolecule(smiles='C')
     mol = Molecule(smiles='C')
     self.assertIsInstance(mol, RMGMolecule)
     self.assertTrue(hasattr(mol, 'id'))
     self.assertFalse(hasattr(rmg_mol, 'id'))
예제 #4
0
    def test_geo_to_mol(self):
        """
        Test that a geometry can be converted to an RMG molecule.
        """
        # Hydrogen
        nums = (1, 1)
        coords = np.array([[0, 0, 0], [0, 0, 0.74]])
        mol = geo_to_mol(coords, nums=nums)
        self.assertIsInstance(mol, Molecule)
        self.assertTrue(mol.to_single_bonds().is_isomorphic(
            Molecule(smiles='[H][H]').to_single_bonds()))

        # Methane
        symbols = ('H', 'C', 'H', 'H', 'H')
        coords = np.array([[0.5288, 0.1610, 0.9359], [0.0000, 0.0000, 0.0000],
                           [0.2051, 0.8240, -0.6786],
                           [0.3345, -0.9314, -0.4496],
                           [-1.0685, -0.0537, 0.1921]])
        mol = geo_to_mol(coords, symbols=symbols)
        self.assertIsInstance(mol, Molecule)
        self.assertTrue(mol.to_single_bonds().is_isomorphic(
            Molecule(smiles='C').to_single_bonds()))