Esempio n. 1
0
    def test_heavy_constraint(self):
        """
        Test that we can constrain the max number of heavy atoms.
        """
        mol1 = Molecule(smiles='CCO')
        self.assertFalse(fails_species_constraints(mol1))

        mol2 = Molecule(smiles='CCN=O')
        self.assertTrue(fails_species_constraints(mol2))
Esempio n. 2
0
    def test_radical_constraint(self):
        """
        Test that we can constrain the max number of radical electrons.
        """
        mol1 = Molecule(smiles='[CH2][CH2]')
        self.assertFalse(fails_species_constraints(mol1))

        mol2 = Molecule(smiles='[CH2][CH][CH2]')
        self.assertTrue(fails_species_constraints(mol2))
Esempio n. 3
0
    def test_sulfur_constraint(self):
        """
        Test that we can constrain the max number of sulfur atoms.
        """
        mol1 = Molecule(smiles='CS')
        self.assertFalse(fails_species_constraints(mol1))

        mol2 = Molecule(smiles='SCS')
        self.assertTrue(fails_species_constraints(mol2))
Esempio n. 4
0
    def test_silicon_constraint(self):
        """
        Test that we can constrain the max number of silicon atoms.
        """
        mol1 = Molecule(smiles='[SiH4]')
        self.assertFalse(fails_species_constraints(mol1))

        mol2 = Molecule(smiles='[SiH3][SiH3]')
        self.assertTrue(fails_species_constraints(mol2))
Esempio n. 5
0
    def test_nitrogen_constraint(self):
        """
        Test that we can constrain the max number of nitrogen atoms.
        """
        mol1 = Molecule(smiles='CN')
        self.assertFalse(fails_species_constraints(mol1))

        mol2 = Molecule(smiles='NCN')
        self.assertTrue(fails_species_constraints(mol2))
Esempio n. 6
0
    def test_explicitly_allowed_molecules(self):
        """
        Test that we can explicitly allow molecules in species constraints.
        """
        mol = Molecule(smiles='CCCC')
        self.assertTrue(fails_species_constraints(mol))

        self.rmg.species_constraints['explicitlyAllowedMolecules'] = [Molecule(smiles='CCCC')]
        self.assertFalse(fails_species_constraints(mol))
Esempio n. 7
0
    def test_surface_site_constraint(self):
        """
        Test that we can constrain the max number of surface sites.
        """

        mol_1site = Molecule().from_adjacency_list("""
1 O u0 p2 c0 {2,D}
2 C u0 p0 c0 {1,D} {3,D}
3 X u0 p0 c0 {2,D}
""")
        mol_2site = Molecule().from_adjacency_list("""
1 C u0 p0 c0 {2,D} {3,D}
2 C u0 p0 c0 {1,D} {4,D}
3 X u0 p0 c0 {1,D}
4 X u0 p0 c0 {2,D}
""")

        mol_3site_vdW = Molecule().from_adjacency_list("""
1 C u0 p0 c0 {2,D} {3,D}
2 C u0 p0 c0 {1,D} {4,D}
3 X u0 p0 c0 {1,D}
4 X u0 p0 c0 {2,D}
6 X u0 p0 c0
""")

        mol_3site = Molecule().from_adjacency_list("""
1 C u0 p0 c0 {4,S} {2,D} {7,S}
2 C u0 p0 c0 {1,D} {3,S} {8,S}
3 C u0 p0 c0 {2,S} {5,S} {6,S} {9,S}
4 H u0 p0 c0 {1,S}
5 H u0 p0 c0 {3,S}
6 H u0 p0 c0 {3,S}
7 X u0 p0 c0 {1,S}
8 X u0 p0 c0 {2,S}
9 X u0 p0 c0 {3,S}
""")
        max_carbon = self.rmg.species_constraints['maximumCarbonAtoms']
        max_heavy_atoms = self.rmg.species_constraints['maximumHeavyAtoms']

        self.rmg.species_constraints['maximumCarbonAtoms'] = 3
        self.rmg.species_constraints['maximumHeavyAtoms'] = 6

        self.assertFalse(fails_species_constraints(mol_1site))
        self.assertFalse(fails_species_constraints(mol_2site))

        self.assertTrue(fails_species_constraints(mol_3site_vdW))
        self.assertTrue(fails_species_constraints(mol_3site))

        self.rmg.species_constraints['maximumCarbonAtoms'] = max_carbon
        self.rmg.species_constraints['maximumHeavyAtoms'] = max_heavy_atoms
Esempio n. 8
0
    def test_species_input(self):
        """
        Test that fails_species_constraints can handle a Species object.
        """
        spc = Species().from_smiles('C')

        self.assertFalse(fails_species_constraints(spc))
Esempio n. 9
0
    def test_carbene_constraint(self):
        """
        Test that we can constrain the max number of singlet carbenes.
        """
        mol1 = Molecule().from_adjacency_list("""
1 C u0 p1 c0 {2,S} {3,S}
2 H u0 p0 c0 {1,S}
3 H u0 p0 c0 {1,S}
""")
        self.assertFalse(fails_species_constraints(mol1))

        mol2 = Molecule().from_adjacency_list("""
1 C u0 p1 c0 {2,S} {3,S}
2 H u0 p0 c0 {1,S}
3 C u0 p1 c0 {1,S} {4,S}
4 H u0 p0 c0 {3,S}
""")
        self.assertTrue(fails_species_constraints(mol2))
Esempio n. 10
0
    def test_carbene_radical_constraint(self):
        """
        Test that we can constrain the max number of radical electrons with a carbene.
        """
        mol1 = Molecule().from_adjacency_list("""
1 C u0 p1 c0 {2,S} {3,S}
2 H u0 p0 c0 {1,S}
3 H u0 p0 c0 {1,S}
""")
        self.assertFalse(fails_species_constraints(mol1))

        mol2 = Molecule().from_adjacency_list("""
1 C u0 p1 c0 {2,S} {3,S}
2 H u0 p0 c0 {1,S}
3 C u1 p0 c0 {1,S} {4,S} {5,S}
4 H u0 p0 c0 {3,S}
5 H u0 p0 c0 {3,S}
""")
        self.assertTrue(fails_species_constraints(mol2))
Esempio n. 11
0
    def test_constraints_not_loaded(self, mock_logging):
        """
        Test what happens when constraints are not loaded.
        """
        # Reset module level rmg variable in rmgpy.rmg.input
        rmgpy.rmg.input.rmg = None

        mol = Molecule(smiles='C')

        self.assertFalse(fails_species_constraints(mol))

        mock_logging.debug.assert_called_with('Species constraints could not be found.')

        # Restore module level rmg variable in rmgpy.rmg.input
        rmgpy.rmg.input.rmg = self.rmg