コード例 #1
0
ファイル: moleculeTest.py プロジェクト: alui1/RMG-Py
    def testCarbeneIdentifiers(self):
        """
        Test that singlet carbene molecules, bearing an electron pair rather than unpaired electrons
        are correctly converted into rdkit molecules and identifiers.
        """
        

        ch2_t = '''
        multiplicity 3
        1 C u2 p0 c0 {2,S} {3,S}
        2 H u0 p0 c0 {1,S}
        3 H u0 p0 c0 {1,S}
        '''
        
        mol = Molecule().fromAdjacencyList(ch2_t)
    
        self.assertEqual( mol.toAugmentedInChI(), 'InChI=1S/CH2/h1H2/mult3')
        self.assertEqual( mol.toSMILES(), '[CH2]')
        

        ch2_s = '''
        multiplicity 1
        1 C u0 p1 c0 {2,S} {3,S}
        2 H u0 p0 c0 {1,S}
        3 H u0 p0 c0 {1,S}
        '''
        
        mol = Molecule().fromAdjacencyList(ch2_s)
        self.assertEqual( mol.toAugmentedInChI(), 'InChI=1S/CH2/h1H2/mult1')
        self.assertEqual( mol.toSMILES(), '[CH2]')
コード例 #2
0
    def testCarbeneIdentifiers(self):
        """
        Test that singlet carbene molecules, bearing an electron pair rather than unpaired electrons
        are correctly converted into rdkit molecules and identifiers.
        """

        ch2_t = '''
        multiplicity 3
        1 C u2 p0 c0 {2,S} {3,S}
        2 H u0 p0 c0 {1,S}
        3 H u0 p0 c0 {1,S}
        '''

        mol = Molecule().fromAdjacencyList(ch2_t)

        self.assertEqual(mol.toAugmentedInChI(), 'InChI=1S/CH2/h1H2/mult3')
        self.assertEqual(mol.toSMILES(), '[CH2]')

        ch2_s = '''
        multiplicity 1
        1 C u0 p1 c0 {2,S} {3,S}
        2 H u0 p0 c0 {1,S}
        3 H u0 p0 c0 {1,S}
        '''

        mol = Molecule().fromAdjacencyList(ch2_s)
        self.assertEqual(mol.toAugmentedInChI(), 'InChI=1S/CH2/h1H2/mult1')
        self.assertEqual(mol.toSMILES(), '[CH2]')
コード例 #3
0
ファイル: adjlistTest.py プロジェクト: connie/RMG-Py
    def testHelium(self):
        """
        adjlist: Test that the adjlist reading and writing works with Helium.
        """
        smiles = '[He]'
        inchi = 'InChI=1S/He'
        adjlist = '1 He u0 p1 c0'
        adjlist_old = '1 He 0'
        adjlist_intermediate = '1 He 0 1'

        mol_smiles = Molecule().fromSMILES(smiles)
        mol_inchi = Molecule().fromInChI(inchi)
        mol = Molecule().fromAdjacencyList(adjlist)
        mol_old = Molecule().fromAdjacencyList(adjlist_old)
        mol_intermediate = Molecule().fromAdjacencyList(adjlist_intermediate)

        # Isomorphic check
        self.assertTrue(mol_smiles.isIsomorphic(mol))
        self.assertTrue(mol_smiles.isIsomorphic(mol_inchi))
        self.assertTrue(mol_smiles.isIsomorphic(mol_old))
        self.assertTrue(mol_smiles.isIsomorphic(mol_intermediate))

        # Adjlist check
        self.assertEqual(mol_smiles.toAdjacencyList().strip(), adjlist)
        self.assertEqual(mol_inchi.toAdjacencyList().strip(), adjlist)
        self.assertEqual(mol.toAdjacencyList().strip(), adjlist)
        self.assertEqual(mol_old.toAdjacencyList().strip(), adjlist)
        self.assertEqual(mol_intermediate.toAdjacencyList().strip(), adjlist)

        self.assertEqual(mol.toSMILES(), smiles)
        self.assertEqual(mol.toInChI(), 'InChI=1S/He')
コード例 #4
0
ファイル: adjlistTest.py プロジェクト: PengZhang13/RMG-Py
 def testHelium(self):
     """
     adjlist: Test that the adjlist reading and writing works with Helium.
     """
     smiles = '[He]'
     inchi = 'InChI=1S/He'
     adjlist = '1 He u0 p1 c0'
     adjlist_old = '1 He 0'
     adjlist_intermediate = '1 He 0 1'
     
     mol_smiles = Molecule().fromSMILES(smiles)
     mol_inchi = Molecule().fromInChI(inchi)
     mol = Molecule().fromAdjacencyList(adjlist)
     mol_old = Molecule().fromAdjacencyList(adjlist_old)
     mol_intermediate = Molecule().fromAdjacencyList(adjlist_intermediate)
     
     # Isomorphic check
     self.assertTrue(mol_smiles.isIsomorphic(mol))
     self.assertTrue(mol_smiles.isIsomorphic(mol_inchi))
     self.assertTrue(mol_smiles.isIsomorphic(mol_old))
     self.assertTrue(mol_smiles.isIsomorphic(mol_intermediate))
     
     # Adjlist check
     self.assertEqual(mol_smiles.toAdjacencyList().strip(), adjlist)
     self.assertEqual(mol_inchi.toAdjacencyList().strip(), adjlist)
     self.assertEqual(mol.toAdjacencyList().strip(), adjlist)
     self.assertEqual(mol_old.toAdjacencyList().strip(), adjlist)
     self.assertEqual(mol_intermediate.toAdjacencyList().strip(), adjlist)
     
     self.assertEqual(mol.toSMILES(),smiles)
     self.assertEqual(mol.toInChI(),'InChI=1S/He')
コード例 #5
0
    def toSMILES(self):

        cutting_label_list = []
        for vertex in self.vertices:
            if isinstance(vertex, CuttingLabel):
                cutting_label_list.append(vertex.symbol)

        SMILES_before = self.copy(deep=True)
        final_vertices = []
        for ind, atom in enumerate(SMILES_before.atoms):
            element_symbol = atom.symbol
            if isinstance(atom, CuttingLabel):
                substi_name = 'Si'
                substi = Atom(element=substi_name)
                substi.label = element_symbol

                for bondedAtom, bond in atom.edges.iteritems():
                    new_bond = Bond(bondedAtom, substi, order=bond.order)

                    bondedAtom.edges[substi] = new_bond
                    del bondedAtom.edges[atom]

                    substi.edges[bondedAtom] = new_bond

                substi.radicalElectrons = 3

                final_vertices.append(substi)
            else:
                final_vertices.append(atom)

        SMILES_before.vertices = final_vertices
        mol_repr = Molecule()
        mol_repr.atoms = SMILES_before.vertices
        SMILES_after = mol_repr.toSMILES()
        import re
        smiles = re.sub('\[Si\]', '', SMILES_after)

        return smiles
コード例 #6
0
    def test_restart(self):
        """
        Test restarting ARC through the ARC class in main.py via the input_dict argument of the API
        Rather than through ARC.py. Check that all files are in place and tst file content.
        """
        restart_path = os.path.join(arc_path, 'arc', 'testing', 'restart(H,H2O2,N2H3,CH3CO2).yml')
        project = 'arc_project_for_testing_delete_after_usage2'
        project_directory = os.path.join(arc_path, 'Projects', project)
        arc1 = ARC(project=project, ess_settings=dict(),
                   input_dict=restart_path, project_directory=project_directory)
        arc1.execute()

        with open(os.path.join(project_directory, 'output', 'thermo.info'), 'r') as f:
            thermo_sft_ccsdtf12_bac = False
            for line in f.readlines():
                if 'thermo_DFT_CCSDTF12_BAC' in line:
                    thermo_sft_ccsdtf12_bac = True
                    break
        self.assertTrue(thermo_sft_ccsdtf12_bac)

        with open(os.path.join(project_directory, 'arc_project_for_testing_delete_after_usage2.info'), 'r') as f:
            sts, n2h3, oet, lot, ap = False, False, False, False, False
            for line in f.readlines():
                if 'Considered the following species and TSs:' in line:
                    sts = True
                elif 'Species N2H3' in line:
                    n2h3 = True
                elif 'Overall time since project initiation:' in line:
                    oet = True
                elif 'Levels of theory used:' in line:
                    lot = True
                elif 'ARC project arc_project_for_testing_delete_after_usage2' in line:
                    ap = True
        self.assertTrue(sts)
        self.assertTrue(n2h3)
        self.assertTrue(oet)
        self.assertTrue(lot)
        self.assertTrue(ap)

        with open(os.path.join(project_directory, 'arc.log'), 'r') as f:
            aei, ver, git, spc, rtm, ldb, therm, src, ter = False, False, False, False, False, False, False, False, False
            for line in f.readlines():
                if 'ARC execution initiated on' in line:
                    aei = True
                elif '#   Version:' in line:
                    ver = True
                elif 'The current git HEAD for ARC is:' in line:
                    git = True
                elif 'Considering species: CH3CO2_rad' in line:
                    spc = True
                elif 'All jobs for species N2H3 successfully converged. Run time: 1:16:03' in line:
                    rtm = True
                elif 'Loading the RMG database...' in line:
                    ldb = True
                elif 'Thermodynamics for H2O2:' in line:
                    therm = True
                elif 'Sources of thermoproperties determined by RMG for the parity plots:' in line:
                    src = True
                elif 'ARC execution terminated on' in line:
                    ter = True
        self.assertTrue(aei)
        self.assertTrue(ver)
        self.assertTrue(git)
        self.assertTrue(spc)
        self.assertTrue(rtm)
        self.assertTrue(ldb)
        self.assertTrue(therm)
        self.assertTrue(src)
        self.assertTrue(ter)

        self.assertTrue(os.path.isfile(os.path.join(project_directory, 'output', 'thermo_parity_plots.pdf')))

        with open(os.path.join(project_directory, 'output', 'Species', 'H2O2', 'species_dictionary.txt'), 'r') as f:
            lines = f.readlines()
        adj_list = str(''.join([line for line in lines if (line and 'H2O2' not in line)]))
        mol1 = Molecule().fromAdjacencyList(adj_list)
        self.assertEqual(mol1.toSMILES(), str('OO'))

        thermo_library_path = os.path.join(project_directory, 'output', 'RMG libraries', 'thermo',
                                           'arc_project_for_testing_delete_after_usage2.py')
        new_thermo_library_path = os.path.join(settings['database.directory'], 'thermo', 'libraries',
                                               'arc_project_for_testing_delete_after_usage2.py')
        # copy the generated library to RMG-database
        shutil.copyfile(thermo_library_path, new_thermo_library_path)
        db = RMGDatabase()
        db.load(
            path=settings['database.directory'],
            thermoLibraries=[str('arc_project_for_testing_delete_after_usage2')],
            transportLibraries=[],
            reactionLibraries=[],
            seedMechanisms=[],
            kineticsFamilies='none',
            kineticsDepositories=[],
            statmechLibraries=None,
            depository=False,
            solvation=False,
            testing=True,
        )

        spc2 = Species().fromSMILES(str('CC([O])=O'))
        spc2.generate_resonance_structures()
        spc2.thermo = db.thermo.getThermoData(spc2)
        self.assertAlmostEqual(spc2.getEnthalpy(298), -178003.44650359568, 1)
        self.assertAlmostEqual(spc2.getEntropy(298), 283.5983103176096, 1)
        self.assertAlmostEqual(spc2.getHeatCapacity(1000), 118.99753808225603, 1)
        self.assertTrue('arc_project_for_testing_delete_after_usage2' in spc2.thermo.comment)

        # delete the generated library from RMG-database
        os.remove(new_thermo_library_path)
コード例 #7
0
    def test_aromatics(self):
        """Test that different aromatics representations returns different SMILES."""
        mol1 = Molecule().fromAdjacencyList("""
1  O u0 p2 c0 {6,S} {9,S}
2  C u0 p0 c0 {3,D} {5,S} {11,S}
3  C u0 p0 c0 {2,D} {4,S} {12,S}
4  C u0 p0 c0 {3,S} {6,D} {13,S}
5  C u0 p0 c0 {2,S} {7,D} {10,S}
6  C u0 p0 c0 {1,S} {4,D} {7,S}
7  C u0 p0 c0 {5,D} {6,S} {8,S}
8  C u0 p0 c0 {7,S} {14,S} {15,S} {16,S}
9  H u0 p0 c0 {1,S}
10 H u0 p0 c0 {5,S}
11 H u0 p0 c0 {2,S}
12 H u0 p0 c0 {3,S}
13 H u0 p0 c0 {4,S}
14 H u0 p0 c0 {8,S}
15 H u0 p0 c0 {8,S}
16 H u0 p0 c0 {8,S}
""")
        mol2 = Molecule().fromAdjacencyList("""
1  O u0 p2 c0 {6,S} {9,S}
2  C u0 p0 c0 {3,S} {5,D} {11,S}
3  C u0 p0 c0 {2,S} {4,D} {12,S}
4  C u0 p0 c0 {3,D} {6,S} {13,S}
5  C u0 p0 c0 {2,D} {7,S} {10,S}
6  C u0 p0 c0 {1,S} {4,S} {7,D}
7  C u0 p0 c0 {5,S} {6,D} {8,S}
8  C u0 p0 c0 {7,S} {14,S} {15,S} {16,S}
9  H u0 p0 c0 {1,S}
10 H u0 p0 c0 {5,S}
11 H u0 p0 c0 {2,S}
12 H u0 p0 c0 {3,S}
13 H u0 p0 c0 {4,S}
14 H u0 p0 c0 {8,S}
15 H u0 p0 c0 {8,S}
16 H u0 p0 c0 {8,S}
""")
        mol3 = Molecule().fromAdjacencyList("""
1  O u0 p2 c0 {6,S} {9,S}
2  C u0 p0 c0 {3,B} {5,B} {11,S}
3  C u0 p0 c0 {2,B} {4,B} {12,S}
4  C u0 p0 c0 {3,B} {6,B} {13,S}
5  C u0 p0 c0 {2,B} {7,B} {10,S}
6  C u0 p0 c0 {1,S} {4,B} {7,B}
7  C u0 p0 c0 {5,B} {6,B} {8,S}
8  C u0 p0 c0 {7,S} {14,S} {15,S} {16,S}
9  H u0 p0 c0 {1,S}
10 H u0 p0 c0 {5,S}
11 H u0 p0 c0 {2,S}
12 H u0 p0 c0 {3,S}
13 H u0 p0 c0 {4,S}
14 H u0 p0 c0 {8,S}
15 H u0 p0 c0 {8,S}
16 H u0 p0 c0 {8,S}
""")

        smiles1 = mol1.toSMILES()
        smiles2 = mol2.toSMILES()
        smiles3 = mol3.toSMILES()

        self.assertNotEqual(smiles1, smiles2)
        self.assertNotEqual(smiles2, smiles3)
        self.assertNotEqual(smiles1, smiles3)
コード例 #8
0
    def test_empty_molecule(self):
        """Test that we can safely return a blank identifier for an empty molecule."""
        mol = Molecule()

        self.assertEqual(mol.toSMILES(), '')
        self.assertEqual(mol.toInChI(), '')
コード例 #9
0
 def compare(self, adjlist, smiles):
     mol = Molecule().fromAdjacencyList(adjlist)
     self.assertEquals(smiles, mol.toSMILES())
コード例 #10
0
    def test_aromatics(self):
        """Test that different aromatics representations returns different SMILES."""
        mol1 = Molecule().fromAdjacencyList("""
1  O u0 p2 c0 {6,S} {9,S}
2  C u0 p0 c0 {3,D} {5,S} {11,S}
3  C u0 p0 c0 {2,D} {4,S} {12,S}
4  C u0 p0 c0 {3,S} {6,D} {13,S}
5  C u0 p0 c0 {2,S} {7,D} {10,S}
6  C u0 p0 c0 {1,S} {4,D} {7,S}
7  C u0 p0 c0 {5,D} {6,S} {8,S}
8  C u0 p0 c0 {7,S} {14,S} {15,S} {16,S}
9  H u0 p0 c0 {1,S}
10 H u0 p0 c0 {5,S}
11 H u0 p0 c0 {2,S}
12 H u0 p0 c0 {3,S}
13 H u0 p0 c0 {4,S}
14 H u0 p0 c0 {8,S}
15 H u0 p0 c0 {8,S}
16 H u0 p0 c0 {8,S}
""")
        mol2 = Molecule().fromAdjacencyList("""
1  O u0 p2 c0 {6,S} {9,S}
2  C u0 p0 c0 {3,S} {5,D} {11,S}
3  C u0 p0 c0 {2,S} {4,D} {12,S}
4  C u0 p0 c0 {3,D} {6,S} {13,S}
5  C u0 p0 c0 {2,D} {7,S} {10,S}
6  C u0 p0 c0 {1,S} {4,S} {7,D}
7  C u0 p0 c0 {5,S} {6,D} {8,S}
8  C u0 p0 c0 {7,S} {14,S} {15,S} {16,S}
9  H u0 p0 c0 {1,S}
10 H u0 p0 c0 {5,S}
11 H u0 p0 c0 {2,S}
12 H u0 p0 c0 {3,S}
13 H u0 p0 c0 {4,S}
14 H u0 p0 c0 {8,S}
15 H u0 p0 c0 {8,S}
16 H u0 p0 c0 {8,S}
""")
        mol3 = Molecule().fromAdjacencyList("""
1  O u0 p2 c0 {6,S} {9,S}
2  C u0 p0 c0 {3,B} {5,B} {11,S}
3  C u0 p0 c0 {2,B} {4,B} {12,S}
4  C u0 p0 c0 {3,B} {6,B} {13,S}
5  C u0 p0 c0 {2,B} {7,B} {10,S}
6  C u0 p0 c0 {1,S} {4,B} {7,B}
7  C u0 p0 c0 {5,B} {6,B} {8,S}
8  C u0 p0 c0 {7,S} {14,S} {15,S} {16,S}
9  H u0 p0 c0 {1,S}
10 H u0 p0 c0 {5,S}
11 H u0 p0 c0 {2,S}
12 H u0 p0 c0 {3,S}
13 H u0 p0 c0 {4,S}
14 H u0 p0 c0 {8,S}
15 H u0 p0 c0 {8,S}
16 H u0 p0 c0 {8,S}
""")

        smiles1 = mol1.toSMILES()
        smiles2 = mol2.toSMILES()
        smiles3 = mol3.toSMILES()

        self.assertNotEqual(smiles1, smiles2)
        self.assertNotEqual(smiles2, smiles3)
        self.assertNotEqual(smiles1, smiles3)
コード例 #11
0
    def test_empty_molecule(self):
        """Test that we can safely return a blank identifier for an empty molecule."""
        mol = Molecule()

        self.assertEqual(mol.toSMILES(), '')
        self.assertEqual(mol.toInChI(), '')
コード例 #12
0
 def compare(self, adjlist, smiles):
     mol = Molecule().fromAdjacencyList(adjlist)
     self.assertEquals(smiles, mol.toSMILES())