def testSaveState(self): fName = os.path.join(RDConfig.RDCodeDir, 'ML/Descriptors/test_data', 'molcalc.dsc') with open(fName, 'r') as inTF: buf = inTF.read().replace('\r\n', '\n').encode('utf-8') inTF.close() inF = BytesIO(buf) calc = cPickle.load(inF) self.assertEqual(calc.GetDescriptorNames(), tuple(self.descs)) self.assertEqual(calc.GetDescriptorVersions(), tuple(self.vers)) self._testVals(calc, self.testD) f = StringIO() with redirect_stdout(f): calc.ShowDescriptors() s = f.getvalue() for name in calc.GetDescriptorNames(): self.assertIn(name, s) self.assertIn('Wildman-Crippen LogP value', calc.GetDescriptorSummaries()) self.assertIn('N/A', calc.GetDescriptorSummaries()) funcs = calc.GetDescriptorFuncs() self.assertEqual(len(funcs), len(self.descs)) for f in funcs: self.assertTrue(callable(f))
def test1(self): # " testing pruning with known results " oPts = [ [0, 0, 1, 0], [0, 1, 1, 1], [1, 0, 1, 1], [1, 1, 0, 0], [1, 1, 1, 1], ] tPts = oPts + [[0, 1, 1, 0], [0, 1, 1, 0]] tree = ID3.ID3Boot(oPts, attrs=range(3), nPossibleVals=[2] * 4) err, badEx = CrossValidate.CrossValidate(tree, oPts) assert err == 0.0, 'bad initial error' assert len(badEx) == 0, 'bad initial error' # prune with original data, shouldn't do anything f = StringIO() with redirect_stdout(f): PruneTree._verbose = True newTree, err = PruneTree.PruneTree(tree, [], oPts) PruneTree._verbose = False self.assertIn('Pruner', f.getvalue()) assert newTree == tree, 'improper pruning' # prune with train data newTree, err = PruneTree.PruneTree(tree, [], tPts) assert newTree != tree, 'bad pruning' assert feq(err, 0.14286), 'bad error result'
def test_all_numeric_with_no_numeric_columns(self): sio = StringIO() PandasTools.WriteSDF(self.df, sio, allNumeric=True) s = sio.getvalue() self.assertFalse(">" in s, s) self.assertNotIn("7\n\n", s) # double-check that the numeric tests don't pass by accident self.assertNotIn("8\n\n", s)
def test_exampleCode(self): # We make sure that the example code runs f = StringIO() with redirect_stdout(f): _exampleCode() s = f.getvalue() self.assertIn('[58, 75, 78, 84]', s)
def _toSVG(mol): if not ipython_useSVG: return None if hasattr(mol, '__sssAtoms'): highlightAtoms = mol.__sssAtoms else: highlightAtoms = [] try: mol.GetAtomWithIdx(0).GetExplicitValence() except RuntimeError: mol.UpdatePropertyCache(False) mc = copy.deepcopy(mol) sio = StringIO() try: Draw.MolToFile(mc, sio, size=molSize, imageType="svg", kekulize=kekulizeStructures, highlightAtoms=highlightAtoms) except ValueError: # <- can happen on a kekulization failure mc = copy.deepcopy(mol) Draw.MolToFile(mc, sio, size=molSize, kekulize=False, highlightAtoms=highlightAtoms, imageType="svg") # It seems that the svg renderer used doesn't quite hit the spec. # Here are some fixes to make it work in the notebook, although I think # the underlying issue needs to be resolved at the generation step svg_split = sio.getvalue().replace("svg:", "").splitlines() header = ('<svg version="1.1" xmlns="http://www.w3.org/2000/svg"' 'width="%dpx" height="%dpx">') % molSize svg = "\n".join(svg_split[:1] + [header] + svg_split[5:]) return svg
def test_Cluster(self): """ tests the Cluster class functionality """ root = Clusters.Cluster(index=1, position=1) c1 = Clusters.Cluster(index=10, position=10) c1.AddChild(Clusters.Cluster(index=30, position=30)) c1.AddChild(Clusters.Cluster(index=31, position=31)) t32 = Clusters.Cluster(index=32, position=32) c1.AddChild(t32) c2 = Clusters.Cluster(index=11) # c2.AddChild(Clusters.Cluster(index=40)) # c2.AddChild(Clusters.Cluster(index=41)) c2.AddChildren( [Clusters.Cluster(index=40), Clusters.Cluster(index=41)]) root.AddChild(c1) root.AddChild(c2) nodes = ClusterUtils.GetNodeList(root) indices = [x.GetIndex() for x in nodes] assert indices == [30, 31, 32, 10, 40, 41, 11, 1], 'bad indices' subtree = root.FindSubtree(11) self.assertEqual( [x.GetIndex() for x in ClusterUtils.GetNodeList(subtree)], [40, 41, 11]) self.assertFalse(root.IsTerminal()) self.assertTrue(t32.IsTerminal()) self.assertEqual(root.GetData(), None) root.SetData(3.14) self.assertEqual(root.GetData(), 3.14) self.assertEqual(root.GetMetric(), 0.0) root.SetMetric(0.1) self.assertEqual(root.GetMetric(), 0.1) self.assertEqual(root.GetIndex(), 1) root.SetIndex(100) self.assertEqual(root.GetIndex(), 100) self.assertEqual(root.GetPointsPositions(), [30, 31, 32, []]) root.RemoveChild(c1) self.assertEqual( [x.GetIndex() for x in ClusterUtils.GetNodeList(root)], [40, 41, 11, 100]) self.assertEqual(root.GetName(), 'Cluster(100)') root.SetName('abc') self.assertEqual(root.GetName(), 'abc') f = StringIO() with redirect_stdout(f): root.Print(showData=True) self.assertIn('abc', f.getvalue()) self.assertIn('Cluster(41)', f.getvalue()) self.assertIn('Metric', f.getvalue())
def test_exampleCode(self): # We make sure that the example code runs from rdkit.TestRunner import redirect_stdout f = StringIO() with redirect_stdout(f): Fingerprinter._exampleCode() s = f.getvalue() self.assertIn('NCCc1ccc(O)c(O)c1', s)
def getStreamIO(sdfString): """ Return a StringIO/BytesIO for the string """ if PY3: sio = BytesIO() if sdfString is None else BytesIO( sdfString.encode('utf-8')) else: # pragma: nocover sio = StringIO() if sdfString is None else StringIO(sdfString) return sio
def test_exampleCode(self): # We make sure that the example code runs from rdkit.TestRunner import redirect_stdout f = StringIO() with redirect_stdout(f): EState.EState._exampleCode() s = f.getvalue() self.assertIn('CC(N)C(=O)O', s)
def test_all_numeric_with_numeric_columns(self): sio = StringIO() df = self.df df["len"] = df["ID"].map(len) PandasTools.WriteSDF(df, sio, allNumeric=True) s = sio.getvalue() self.assertEqual(s.count("<len>"), 2) self.assertIn("7\n\n", s) self.assertIn("8\n\n", s)
def test_specify_numeric_column(self): sio = StringIO() df = self.df df["len2"] = df["ID"].map(len) PandasTools.WriteSDF(df, sio, properties=["len2"]) s = sio.getvalue() self.assertEqual(s.count("<len2>"), 2) self.assertIn("7\n\n", s) self.assertIn("8\n\n", s)
def test_all_numeric_with_no_numeric_columns(self): sio = StringIO() PandasTools.WriteSDF(self.df, sio, allNumeric=True) s = sio.getvalue() self.assertFalse(">" in s, s) self.assertNotIn( "7\n\n", s) # double-check that the numeric tests don't pass by accident self.assertNotIn("8\n\n", s)
def test_exampleCode(self): try: f = StringIO() with redirect_stdout(f): Tree._exampleCode() self.assertTrue(os.path.isfile('save.pkl')) self.assertIn('tree==tree2 False', f.getvalue(), 'Example didn' 't run to end') finally: if os.path.isfile('save.pkl'): os.remove('save.pkl')
def test_exceptions(self): self.assertRaises(ValueError, SplitData.SplitIndices, 10, -0.1) self.assertRaises(ValueError, SplitData.SplitIndices, 10, 1.1) f = StringIO() with redirect_stdout(f): SplitData.SplitIndices(10, 0.5, replacement=True, silent=False) s = f.getvalue() self.assertIn('Training', s) self.assertIn('hold-out', s)
def test_TestRun(self): try: f = StringIO() with redirect_stdout(f): CrossValidate.TestRun() self.assertTrue(os.path.isfile('save.pkl')) s = f.getvalue() self.assertIn('t1 == t2 True', s) finally: if os.path.isfile('save.pkl'): os.remove('save.pkl')
def test_SaveSMILESFromFrame(self): sio = StringIO() PandasTools.SaveSMILESFromFrame(self.df, sio) result = sio.getvalue() self.assertIn(self.df['SMILES'][10], result) self.assertIn(self.df['ID'][10], result) sio = StringIO() PandasTools.SaveSMILESFromFrame(self.df, sio, NamesCol='PUBCHEM_IUPAC_INCHIKEY') result = sio.getvalue() self.assertIn(self.df['SMILES'][10], result) self.assertIn(self.df['PUBCHEM_IUPAC_INCHIKEY'][10], result)
def testRun(self): # " test that the CrossValidationDriver runs " examples, attrs, nPossibleVals = randomtest.GenRandomExamples(nExamples=200) f = StringIO() with redirect_stdout(f): tree, frac = CrossValidate.CrossValidationDriver(examples, attrs, nPossibleVals, silent=False) self.assertGreater(frac, 0) self.assertEqual('Var: 1', tree.GetName()) self.assertIn('Validation error', f.getvalue()) CrossValidate.CrossValidationDriver(examples, attrs, nPossibleVals, lessGreedy=True, calcTotalError=True, silent=True)
def test_Cluster(self): """ tests the Cluster class functionality """ root = Clusters.Cluster(index=1, position=1) c1 = Clusters.Cluster(index=10, position=10) c1.AddChild(Clusters.Cluster(index=30, position=30)) c1.AddChild(Clusters.Cluster(index=31, position=31)) t32 = Clusters.Cluster(index=32, position=32) c1.AddChild(t32) c2 = Clusters.Cluster(index=11) # c2.AddChild(Clusters.Cluster(index=40)) # c2.AddChild(Clusters.Cluster(index=41)) c2.AddChildren([Clusters.Cluster(index=40), Clusters.Cluster(index=41)]) root.AddChild(c1) root.AddChild(c2) nodes = ClusterUtils.GetNodeList(root) indices = [x.GetIndex() for x in nodes] assert indices == [30, 31, 32, 10, 40, 41, 11, 1], 'bad indices' subtree = root.FindSubtree(11) self.assertEqual([x.GetIndex() for x in ClusterUtils.GetNodeList(subtree)], [40, 41, 11]) self.assertFalse(root.IsTerminal()) self.assertTrue(t32.IsTerminal()) self.assertEqual(root.GetData(), None) root.SetData(3.14) self.assertEqual(root.GetData(), 3.14) self.assertEqual(root.GetMetric(), 0.0) root.SetMetric(0.1) self.assertEqual(root.GetMetric(), 0.1) self.assertEqual(root.GetIndex(), 1) root.SetIndex(100) self.assertEqual(root.GetIndex(), 100) self.assertEqual(root.GetPointsPositions(), [30, 31, 32, []]) root.RemoveChild(c1) self.assertEqual([x.GetIndex() for x in ClusterUtils.GetNodeList(root)], [40, 41, 11, 100]) self.assertEqual(root.GetName(), 'Cluster(100)') root.SetName('abc') self.assertEqual(root.GetName(), 'abc') f = StringIO() with redirect_stdout(f): root.Print(showData=True) self.assertIn('abc', f.getvalue()) self.assertIn('Cluster(41)', f.getvalue()) self.assertIn('Metric', f.getvalue())
def DatabaseToDatabase(fromDb, fromTbl, toDb, toTbl, fields='*', join='', where='', user='******', password='******', keyCol=None, nullMarker='None'): """ FIX: at the moment this is a hack """ sio = StringIO() sio.write( DatabaseToText(fromDb, fromTbl, fields=fields, join=join, where=where, user=user, password=password)) sio.seek(0) TextFileToDatabase(toDb, toTbl, sio, user=user, password=password, keyCol=keyCol, nullMarker=nullMarker)
def test_SplitData(self): self.assertRaises(ValueError, SplitData.SplitDataSet, None, -1.1) self.assertRaises(ValueError, SplitData.SplitDataSet, None, 1.1) data = list(range(10)) DataUtils.InitRandomNumbers((23, 42)) f = StringIO() with redirect_stdout(f): result = SplitData.SplitDataSet(data, 0.5) self.assertEqual(set(result[0]).intersection(result[1]), set()) self.assertEqual(len(result[0]), 5) s = f.getvalue() self.assertIn('Training', s) self.assertIn('hold-out', s)
def test_Tree(self): tree = Tree.TreeNode(None, 'root', label=0) self.assertEqual(tree.GetLevel(), 0) self.assertEqual(tree.GetName(), 'root') self.assertEqual(tree.GetData(), None) self.assertEqual(tree.GetTerminal(), False) self.assertEqual(tree.GetLabel(), 0) self.assertEqual(tree.GetParent(), None) self.assertEqual(tree.GetChildren(), []) for i in range(3): child = tree.AddChild('child {0}'.format(i), i + 1, data={'key': 'value'}) self.assertEqual(child.GetLevel(), 1) self.assertEqual(child.GetName(), 'child {0}'.format(i)) self.assertEqual(child.GetData(), {'key': 'value'}) self.assertEqual(child.GetLabel(), i + 1) self.assertEqual(child.GetParent(), tree) self.assertEqual(child.GetChildren(), []) children = tree.GetChildren() self.assertEqual(len(children), 3) children[0].AddChild('terminal', 4, isTerminal=True) s = str(tree) self.assertIn('root', s) self.assertIn(' terminal', s) self.assertIn(' child 2', s) tree.NameTree(['a', 'b', 'c', 'd', 'e']) self.assertEqual(str(tree), 'a\n b\n terminal\n c\n d\n') tree.PruneChild(children[1]) self.assertEqual(str(tree), 'a\n b\n terminal\n d\n') f = StringIO() with redirect_stdout(f): tree.Print(showData=True) s = f.getvalue() self.assertIn('value', s) self.assertIn('None', s) f = StringIO() with redirect_stdout(f): tree.Print() s = f.getvalue() self.assertNotIn('value', s) self.assertNotIn('None', s) tree.Destroy() self.assertEqual(str(tree), 'a\n')
def test_SmilesOutput(self): smis = ['C1CCC1', 'C1CC1', 'C=O', 'CCN'] mols = [Chem.MolFromSmiles(x) for x in smis] for i, mol in enumerate(mols, 100): mol.SetProp('ID', str(i)) suppl1 = SupplyNode(contents=mols) suppl2 = SupplyNode(contents='abcd') sio = StringIO() node = SmilesOutput.OutputNode(idField='ID', dest=sio, delim=', ') node.AddParent(suppl1) node.AddParent(suppl2) list(node) self.assertEqual(sio.getvalue(), '100, C1CCC1, a\n101, C1CC1, b\n102, C=O, c\n103, CCN, d\n')
def test_DescriptorCalculator(self): calc = Descriptors.DescriptorCalculator() self.assertRaises(NotImplementedError, calc.ShowDescriptors) self.assertRaises(NotImplementedError, calc.GetDescriptorNames) self.assertRaises(NotImplementedError, calc.CalcDescriptors, None) calc.simpleList = ['simple1', 'simple2'] calc.compoundList = ['cmpd1', 'cmpd2'] f = StringIO() with redirect_stdout(f): calc.ShowDescriptors() s = f.getvalue() for name in calc.simpleList: self.assertIn(name, s) for name in calc.compoundList: self.assertIn(name, s)
def test_SmilesOutput(self): smis = ['C1CCC1', 'C1CC1', 'C=O', 'CCN'] mols = [Chem.MolFromSmiles(x) for x in smis] for i, mol in enumerate(mols, 100): mol.SetProp('ID', str(i)) suppl1 = SupplyNode(contents=mols) suppl2 = SupplyNode(contents='abcd') sio = StringIO() node = SmilesOutput.OutputNode(idField='ID', dest=sio, delim=', ') node.AddParent(suppl1) node.AddParent(suppl2) list(node) self.assertEqual( sio.getvalue(), '100, C1CCC1, a\n101, C1CC1, b\n102, C=O, c\n103, CCN, d\n')
def test_WriteData(self): self.setUpQuantLoad() with contextlib.closing(StringIO()) as f: DataUtils.WriteData(f, self.d.GetVarNames(), self.d.GetQuantBounds(), self.d.data) s = f.getvalue() self.assertIn('DataUtils', s) self.assertIn('foo1', s) self.assertIn('2 2 1 0 1', s)
def test_OutputNode(self): supplier1 = Supply.SupplyNode(contents=[1, 2, 3]) supplier2 = Supply.SupplyNode(contents=["a", "b", "c"]) sio = StringIO() node = Output.OutputNode(dest=sio, strFunc=lambda x: "{0[0]}-{0[1]} ".format(x)) node.AddParent(supplier1) node.AddParent(supplier2) result = list(s for s in node) self.assertEqual(result, [(1, "a"), (2, "b"), (3, "c")]) self.assertEqual(sio.getvalue(), "1-a 2-b 3-c ") sio = StringIO() node = Output.OutputNode(dest=sio) node.AddParent(supplier1) result = list(s for s in node) self.assertEqual(result, [1, 2, 3]) self.assertEqual(sio.getvalue(), "123")
def testRun(self): # " test that the CrossValidationDriver runs " examples, attrs, nPossibleVals = randomtest.GenRandomExamples( nExamples=200) f = StringIO() with redirect_stdout(f): tree, frac = CrossValidate.CrossValidationDriver(examples, attrs, nPossibleVals, silent=False) self.assertGreater(frac, 0) self.assertEqual('Var: 1', tree.GetName()) self.assertIn('Validation error', f.getvalue()) CrossValidate.CrossValidationDriver(examples, attrs, nPossibleVals, lessGreedy=True, calcTotalError=True, silent=True)
def test_exampleCode(self): f = StringIO() with redirect_stdout(f): try: PruneTree._testRandom() self.assertTrue(os.path.isfile('prune.pkl')) finally: if os.path.isfile('orig.pkl'): os.remove('orig.pkl') if os.path.isfile('prune.pkl'): os.remove('prune.pkl') self.assertIn('pruned error', f.getvalue()) f = StringIO() with redirect_stdout(f): PruneTree._testSpecific() self.assertIn('pruned holdout error', f.getvalue()) f = StringIO() with redirect_stdout(f): PruneTree._testChain() self.assertIn('pruned holdout error', f.getvalue())
def test_FeatMapParser(self): # We can use a string p = FeatMapParser.FeatMapParser(data=self.data) fm = p.Parse() self.assertEqual(fm.GetNumFeatures(), 3) self.assertEqual([x.GetFamily() for x in fm.GetFeatures()], ['Acceptor', 'Aromatic', 'Acceptor']) # We can use a list of strings p = FeatMapParser.FeatMapParser(data=self.data.split('\n')) fm = p.Parse() self.assertEqual(fm.GetNumFeatures(), 3) self.assertEqual([x.GetFamily() for x in fm.GetFeatures()], ['Acceptor', 'Aromatic', 'Acceptor']) # and a stream with closing(StringIO(self.data)) as file: p = FeatMapParser.FeatMapParser(file=file) fm = p.Parse() self.assertEqual(fm.GetNumFeatures(), 3) self.assertEqual([x.GetFamily() for x in fm.GetFeatures()], ['Acceptor', 'Aromatic', 'Acceptor'])
def test_OutputNode(self): supplier1 = Supply.SupplyNode(contents=[1, 2, 3]) supplier2 = Supply.SupplyNode(contents=['a', 'b', 'c']) sio = StringIO() node = Output.OutputNode(dest=sio, strFunc=lambda x: '{0[0]}-{0[1]} '.format(x)) node.AddParent(supplier1) node.AddParent(supplier2) result = list(s for s in node) self.assertEqual(result, [(1, 'a'), (2, 'b'), (3, 'c')]) self.assertEqual(sio.getvalue(), '1-a 2-b 3-c ') sio = StringIO() node = Output.OutputNode(dest=sio) node.AddParent(supplier1) result = list(s for s in node) self.assertEqual(result, [1, 2, 3]) self.assertEqual(sio.getvalue(), '123')
hist = SubElement(head, "ModelHistory") revision = SubElement(hist, "Revision") tm = time.localtime() date = SubElement(revision, "RevisionDate") elem = SubElement(date, "Year") elem.text = str(tm[0]) elem = SubElement(date, "Month") elem.text = str(tm[1]) elem = SubElement(date, "Day") elem.text = str(tm[2]) note = SubElement(revision, "RevisionNote") note.text = "Created" return ElementTree(head) if __name__ == '__main__': # pragma: nocover import sys from rdkit.six.moves import cPickle # @UnresolvedImport from rdkit.six import StringIO pkg = cPickle.load(open(sys.argv[1], 'rb')) perf = (.80, .95, .70, [[4, 1], [1, 4]]) tree = PackageToXml(pkg, dataPerformance=[('training data performance', perf)]) io = StringIO() tree.write(io) txt = io.getvalue() header = """<?xml version="1.0"?> <!DOCTYPE RDModelInfo PUBLIC "-//RD//DTD RDModelInfo //EN" "RD_Model.dtd"> """ print(header) print(txt.replace('><', '>\n<'))
def test_exampleCode(self): # We make sure that the example code runs f = StringIO() with redirect_stdout(f): Matcher._exampleCode() self.assertIn('finished', f.getvalue())
def test_exampleCode(self): f = StringIO() with redirect_stdout(f): CompoundDescriptors._exampleCode()
def test_default_write_does_not_include_tags(self): sio = StringIO() PandasTools.WriteSDF(self.df, sio) s = sio.getvalue() self.assertNotIn(s, "prop2")
def test_identifier_from_a_column(self): sio = StringIO() PandasTools.WriteSDF(self.df, sio, idName="prop2") s = sio.getvalue() first_line = s.split("\n", 1)[0] self.assertEqual(first_line, "qwe")
def test_exampleCode(self): f = StringIO() with redirect_stdout(f): BuildQuantTree.TestTree() self.assertIn('Var: 2', f.getvalue())
def test3(self): examples = [] bv = ExplicitBitVect(2) vc = VectCollection() vc.AddVect(1, bv) examples.append(['a', vc, 1]) bv = ExplicitBitVect(2) bv.SetBit(1) vc = VectCollection() vc.AddVect(1, bv) examples.append(['c', vc, 0]) bv = ExplicitBitVect(2) bv.SetBit(1) vc = VectCollection() vc.AddVect(1, bv) examples.append(['c2', vc, 0]) bv = ExplicitBitVect(2) bv.SetBit(0) vc = VectCollection() vc.AddVect(1, bv) examples.append(['d', vc, 0]) bv = ExplicitBitVect(2) bv.SetBit(0) vc = VectCollection() vc.AddVect(1, bv) bv = ExplicitBitVect(2) bv.SetBit(1) vc.AddVect(2, bv) examples.append(['d2', vc, 0]) bv = ExplicitBitVect(2) bv.SetBit(0) bv.SetBit(1) vc = VectCollection() vc.AddVect(1, bv) examples.append(['d', vc, 1]) bv = ExplicitBitVect(2) bv.SetBit(0) bv.SetBit(1) vc = VectCollection() vc.AddVect(1, bv) examples.append(['e', vc, 1]) f = StringIO() with redirect_stdout(f): t = BuildSigTree(examples, 2, metric=InfoTheory.InfoType.ENTROPY, maxDepth=2, verbose=True) self.assertIn('Build', f.getvalue()) self.assertEqual(t.GetName(), 'Bit-0') self.assertEqual(t.GetLabel(), 0) c0 = t.GetChildren()[0] self.assertEqual(c0.GetName(), 'Bit-1') self.assertEqual(c0.GetLabel(), 1) c1 = t.GetChildren()[1] self.assertEqual(c1.GetName(), 'Bit-1') self.assertEqual(c1.GetLabel(), 1) bv = ExplicitBitVect(2) bv.SetBit(0) vc = VectCollection() vc.AddVect(1, bv) bv = ExplicitBitVect(2) bv.SetBit(1) vc.AddVect(2, bv) r = t.ClassifyExample(['t', vc, 0]) self.assertEqual(r, 0)
supp3 = Chem.SDMolSupplier('E:/jupyter/cc/20181204-products/a-br.sdf') mol2 = [] mol3 = [] for mol_2 in supp2: mol2.append(mol_2) for mol_3 in supp3: mol3.append(mol_3) print(len(mol2)) print(len(mol3)) print(Chem.MolToSmiles(mol2[2])) print(Chem.MolToSmiles(mol3[0])) # rdkit.Chem.MolStandardize.rdMolStandardize.Uncharger.uncharge 去电荷 from rdkit.Chem.MolStandardize import rdMolStandardize from rdkit.six import StringIO sio = StringIO() w = Chem.SDWriter(sio) rxn = AllChem.ReactionFromSmarts( '[N:2]1(:[C]:[C]([C]):[N:4]:[N:3]:1)[C].[*:8][C:5]#[C:6].[*:7][Br]>>[N:2]1([C:6]=[C:5]([*:8])[N:4]=[N:3]1)[*:7]' ) rxn.GetNumReactantTemplates() x1 = Chem.MolFromSmarts('[N]1(:[C]:[C]([C]):[N]:[N]:1)[C]') #print (len(x)) name = [] product_smiles = [] for i in range(len(mol2)): x2 = mol2[i] for j in range(len(mol3)): x3 = mol3[j] x = rxn.RunReactants((x1, x2, x3))
sio.write( DatabaseToText(fromDb, fromTbl, fields=fields, join=join, where=where, user=user, password=password)) sio.seek(0) TextFileToDatabase(toDb, toTbl, sio, user=user, password=password, keyCol=keyCol, nullMarker=nullMarker) if __name__ == '__main__': # pragma: nocover sio = StringIO() sio.write('foo,bar,baz\n') sio.write('1,2,3\n') sio.write('1.1,4,5\n') sio.write('4,foo,6\n') sio.seek(0) from rdkit import RDConfig import os dirLoc = os.path.join(RDConfig.RDCodeDir, 'Dbase', 'TEST.GDB') TextFileToDatabase(dirLoc, 'fromtext', sio)
def DatabaseToDatabase(fromDb, fromTbl, toDb, toTbl, fields='*', join='', where='', user='******', password='******', keyCol=None, nullMarker='None'): """ FIX: at the moment this is a hack """ sio = StringIO() sio.write( DatabaseToText(fromDb, fromTbl, fields=fields, join=join, where=where, user=user, password=password)) sio.seek(0) TextFileToDatabase(toDb, toTbl, sio, user=user, password=password, keyCol=keyCol, nullMarker=nullMarker) if __name__ == '__main__': # pragma: nocover sio = StringIO() sio.write('foo,bar,baz\n') sio.write('1,2,3\n') sio.write('1.1,4,5\n') sio.write('4,foo,6\n') sio.seek(0) from rdkit import RDConfig import os dirLoc = os.path.join(RDConfig.RDCodeDir, 'Dbase', 'TEST.GDB') TextFileToDatabase(dirLoc, 'fromtext', sio)