mirror of
https://github.com/rdkit/rdkit.git
synced 2026-06-03 21:44:30 +08:00
Issue1071/yapf (#1078)
* Issue #1071: add yapf configuration file * yapf formatting of Code directory * yapf formatting of Contrib directory * yapf formatting of Data directory * yapf formatting of Docs directory * yapf formatting of External directory * yapf formatting of Projects directory * yapf formatting of Regress directory * yapf formatting of Scripts directory * yapf formatting of Web directory * yapf formatting of rdkit directory
This commit is contained in:
284
External/AvalonTools/Wrap/testAvalonTools.py
vendored
284
External/AvalonTools/Wrap/testAvalonTools.py
vendored
@@ -19,208 +19,210 @@ STRUCHK_INIT = '''-tm
|
||||
-cl 3
|
||||
-cs
|
||||
-cn 999
|
||||
-l %(struchk_log_path)sstruchk.log'''%locals()
|
||||
-l %(struchk_log_path)sstruchk.log''' % locals()
|
||||
|
||||
|
||||
def feq(v1, v2, tol=1e-4):
|
||||
return abs(v1 - v2) < tol
|
||||
|
||||
|
||||
def feq(v1,v2,tol=1e-4):
|
||||
return abs(v1-v2)<tol
|
||||
class TestCase(unittest.TestCase):
|
||||
def setUp(self) :
|
||||
|
||||
def setUp(self):
|
||||
pass
|
||||
|
||||
def test1(self):
|
||||
m1 = Chem.MolFromSmiles('c1cccnc1')
|
||||
smi = pyAvalonTools.GetCanonSmiles(m1)
|
||||
self.assertTrue(smi=='c1ccncc1')
|
||||
smi = pyAvalonTools.GetCanonSmiles('c1cccnc1',True)
|
||||
self.assertTrue(smi=='c1ccncc1')
|
||||
|
||||
self.assertTrue(smi == 'c1ccncc1')
|
||||
smi = pyAvalonTools.GetCanonSmiles('c1cccnc1', True)
|
||||
self.assertTrue(smi == 'c1ccncc1')
|
||||
|
||||
def test2(self):
|
||||
tgts=['CC1=CC(=O)C=CC1=O','c2ccc1SC(=Nc1c2)SSC4=Nc3ccccc3S4','[O-][N+](=O)c1cc(Cl)c(O)c(c1)[N+]([O-])=O',
|
||||
'N=C1NC=C(S1)[N+]([O-])=O','Nc3ccc2C(=O)c1ccccc1C(=O)c2c3',
|
||||
'OC(=O)c1ccccc1C3=C2C=CC(=O)C(Br)=C2Oc4c3ccc(O)c4Br','CN(C)C2C(=O)c1ccccc1C(=O)C=2Cl',
|
||||
'Cc3ccc2C(=O)c1ccccc1C(=O)c2c3[N+]([O-])=O',r'C/C(=N\O)/C(/C)=N/O',
|
||||
'c1ccc(cc1)P(c2ccccc2)c3ccccc3']
|
||||
with open(os.path.join(RDConfig.RDDataDir,'NCI','first_200.props.sdf'),'r') as f:
|
||||
tgts = ['CC1=CC(=O)C=CC1=O', 'c2ccc1SC(=Nc1c2)SSC4=Nc3ccccc3S4',
|
||||
'[O-][N+](=O)c1cc(Cl)c(O)c(c1)[N+]([O-])=O', 'N=C1NC=C(S1)[N+]([O-])=O',
|
||||
'Nc3ccc2C(=O)c1ccccc1C(=O)c2c3', 'OC(=O)c1ccccc1C3=C2C=CC(=O)C(Br)=C2Oc4c3ccc(O)c4Br',
|
||||
'CN(C)C2C(=O)c1ccccc1C(=O)C=2Cl', 'Cc3ccc2C(=O)c1ccccc1C(=O)c2c3[N+]([O-])=O',
|
||||
r'C/C(=N\O)/C(/C)=N/O', 'c1ccc(cc1)P(c2ccccc2)c3ccccc3']
|
||||
with open(os.path.join(RDConfig.RDDataDir, 'NCI', 'first_200.props.sdf'), 'r') as f:
|
||||
d = f.read()
|
||||
mbs = d.split('$$$$\n')[:10]
|
||||
smis = [pyAvalonTools.GetCanonSmiles(mb,False) for mb in mbs]
|
||||
self.assertTrue(smis==tgts)
|
||||
smis = [pyAvalonTools.GetCanonSmiles(smi,True) for smi in smis]
|
||||
self.assertTrue(smis==tgts)
|
||||
smis = [pyAvalonTools.GetCanonSmiles(mb, False) for mb in mbs]
|
||||
self.assertTrue(smis == tgts)
|
||||
smis = [pyAvalonTools.GetCanonSmiles(smi, True) for smi in smis]
|
||||
self.assertTrue(smis == tgts)
|
||||
|
||||
def test3(self):
|
||||
bv = pyAvalonTools.GetAvalonFP(Chem.MolFromSmiles('c1ccccn1'))
|
||||
self.assertEqual(len(bv),512)
|
||||
self.assertEqual(bv.GetNumOnBits(),20)
|
||||
self.assertEqual(len(bv), 512)
|
||||
self.assertEqual(bv.GetNumOnBits(), 20)
|
||||
bv = pyAvalonTools.GetAvalonFP(Chem.MolFromSmiles('c1ccccc1'))
|
||||
self.assertEqual(bv.GetNumOnBits(),8)
|
||||
self.assertEqual(bv.GetNumOnBits(), 8)
|
||||
bv = pyAvalonTools.GetAvalonFP(Chem.MolFromSmiles('c1nnccc1'))
|
||||
self.assertEqual(bv.GetNumOnBits(),30)
|
||||
self.assertEqual(bv.GetNumOnBits(), 30)
|
||||
bv = pyAvalonTools.GetAvalonFP(Chem.MolFromSmiles('c1ncncc1'))
|
||||
self.assertEqual(bv.GetNumOnBits(),27)
|
||||
self.assertEqual(bv.GetNumOnBits(), 27)
|
||||
|
||||
bv = pyAvalonTools.GetAvalonFP(Chem.MolFromSmiles('c1ncncc1'),nBits=1024)
|
||||
self.assertEqual(len(bv),1024)
|
||||
self.assertTrue(bv.GetNumOnBits()>27)
|
||||
bv = pyAvalonTools.GetAvalonFP(Chem.MolFromSmiles('c1ncncc1'), nBits=1024)
|
||||
self.assertEqual(len(bv), 1024)
|
||||
self.assertTrue(bv.GetNumOnBits() > 27)
|
||||
|
||||
def test4(self):
|
||||
bv = pyAvalonTools.GetAvalonFP('c1ccccn1',True)
|
||||
self.assertEqual(bv.GetNumOnBits(),20)
|
||||
bv = pyAvalonTools.GetAvalonFP('c1ccccc1',True)
|
||||
self.assertEqual(bv.GetNumOnBits(),8)
|
||||
bv = pyAvalonTools.GetAvalonFP('c1nnccc1',True)
|
||||
self.assertEqual(bv.GetNumOnBits(),30)
|
||||
bv = pyAvalonTools.GetAvalonFP('c1ncncc1',True)
|
||||
self.assertEqual(bv.GetNumOnBits(),27)
|
||||
bv = pyAvalonTools.GetAvalonFP('c1ncncc1',True,nBits=1024)
|
||||
self.assertEqual(len(bv),1024)
|
||||
self.assertTrue(bv.GetNumOnBits()>27)
|
||||
bv = pyAvalonTools.GetAvalonFP('c1ccccn1', True)
|
||||
self.assertEqual(bv.GetNumOnBits(), 20)
|
||||
bv = pyAvalonTools.GetAvalonFP('c1ccccc1', True)
|
||||
self.assertEqual(bv.GetNumOnBits(), 8)
|
||||
bv = pyAvalonTools.GetAvalonFP('c1nnccc1', True)
|
||||
self.assertEqual(bv.GetNumOnBits(), 30)
|
||||
bv = pyAvalonTools.GetAvalonFP('c1ncncc1', True)
|
||||
self.assertEqual(bv.GetNumOnBits(), 27)
|
||||
bv = pyAvalonTools.GetAvalonFP('c1ncncc1', True, nBits=1024)
|
||||
self.assertEqual(len(bv), 1024)
|
||||
self.assertTrue(bv.GetNumOnBits() > 27)
|
||||
|
||||
bv = pyAvalonTools.GetAvalonFP(Chem.MolToMolBlock(Chem.MolFromSmiles('c1ccccn1')),False)
|
||||
self.assertEqual(len(bv),512)
|
||||
self.assertEqual(bv.GetNumOnBits(),20)
|
||||
bv = pyAvalonTools.GetAvalonFP(Chem.MolToMolBlock(Chem.MolFromSmiles('c1ccccc1')),False)
|
||||
self.assertEqual(bv.GetNumOnBits(),8)
|
||||
bv = pyAvalonTools.GetAvalonFP(Chem.MolToMolBlock(Chem.MolFromSmiles('c1ccccn1')), False)
|
||||
self.assertEqual(len(bv), 512)
|
||||
self.assertEqual(bv.GetNumOnBits(), 20)
|
||||
bv = pyAvalonTools.GetAvalonFP(Chem.MolToMolBlock(Chem.MolFromSmiles('c1ccccc1')), False)
|
||||
self.assertEqual(bv.GetNumOnBits(), 8)
|
||||
|
||||
def test4b(self):
|
||||
words = pyAvalonTools.GetAvalonFPAsWords(Chem.MolFromSmiles('c1ccccn1'))
|
||||
words2 = pyAvalonTools.GetAvalonFPAsWords(Chem.MolFromSmiles('Cc1ccccn1'))
|
||||
self.assertEqual(len(words),len(words2))
|
||||
for i,word in enumerate(words):
|
||||
self.assertEqual(word&words2[i],word)
|
||||
self.assertEqual(len(words), len(words2))
|
||||
for i, word in enumerate(words):
|
||||
self.assertEqual(word & words2[i], word)
|
||||
|
||||
def test5(self):
|
||||
m = Chem.MolFromSmiles('c1ccccc1C1(CC1)N')
|
||||
pyAvalonTools.Generate2DCoords(m)
|
||||
self.assertEqual(m.GetNumConformers(),1)
|
||||
self.assertTrue(m.GetConformer(0).Is3D()==False)
|
||||
self.assertEqual(m.GetNumConformers(), 1)
|
||||
self.assertTrue(m.GetConformer(0).Is3D() == False)
|
||||
|
||||
def test6(self):
|
||||
mb=pyAvalonTools.Generate2DCoords('c1ccccc1C1(CC1)N',True)
|
||||
mb = pyAvalonTools.Generate2DCoords('c1ccccc1C1(CC1)N', True)
|
||||
m = Chem.MolFromMolBlock(mb)
|
||||
self.assertEqual(m.GetNumConformers(),1)
|
||||
self.assertTrue(m.GetConformer(0).Is3D()==False)
|
||||
self.assertEqual(m.GetNumConformers(), 1)
|
||||
self.assertTrue(m.GetConformer(0).Is3D() == False)
|
||||
|
||||
def testRDK151(self):
|
||||
smi="C[C@H](F)Cl"
|
||||
smi = "C[C@H](F)Cl"
|
||||
m = Chem.MolFromSmiles(smi)
|
||||
temp = pyAvalonTools.GetCanonSmiles(smi,True)
|
||||
self.assertEqual(temp,smi)
|
||||
temp = pyAvalonTools.GetCanonSmiles(smi, True)
|
||||
self.assertEqual(temp, smi)
|
||||
temp = pyAvalonTools.GetCanonSmiles(m)
|
||||
self.assertEqual(temp,smi)
|
||||
self.assertEqual(temp, smi)
|
||||
|
||||
def testStruChk(self):
|
||||
smi_good='c1ccccc1C1(CC-C(C)C1)C'
|
||||
smi_bad='c1c(R)cccc1C1(CC-C(C)C1)C'
|
||||
smi_good = 'c1ccccc1C1(CC-C(C)C1)C'
|
||||
smi_bad = 'c1c(R)cccc1C1(CC-C(C)C1)C'
|
||||
r = pyAvalonTools.InitializeCheckMol(STRUCHK_INIT)
|
||||
self.assertEqual(r, 0)
|
||||
(err, fixed_mol) = pyAvalonTools.CheckMolecule(smi_good, True)
|
||||
self.assertEqual(err, 0)
|
||||
mol = Chem.MolFromSmiles(smi_good)
|
||||
(err, fixed_mol)=pyAvalonTools.CheckMolecule(mol)
|
||||
mol = Chem.MolFromSmiles(smi_good)
|
||||
(err, fixed_mol) = pyAvalonTools.CheckMolecule(mol)
|
||||
self.assertEqual(err, 0)
|
||||
|
||||
(err, fixed_mol)=pyAvalonTools.CheckMoleculeString(smi_good,True)
|
||||
(err, fixed_mol) = pyAvalonTools.CheckMoleculeString(smi_good, True)
|
||||
self.assertEqual(err, 0)
|
||||
self.assertNotEqual(fixed_mol,"")
|
||||
self.assertTrue(fixed_mol.find('M END')>0)
|
||||
self.assertNotEqual(fixed_mol, "")
|
||||
self.assertTrue(fixed_mol.find('M END') > 0)
|
||||
|
||||
(err, fixed_mol)=pyAvalonTools.CheckMolecule(smi_bad, False)
|
||||
(err, fixed_mol) = pyAvalonTools.CheckMolecule(smi_bad, False)
|
||||
self.assertNotEqual(err, 0)
|
||||
self.assertFalse(fixed_mol)
|
||||
|
||||
(err, fixed_mol)=pyAvalonTools.CheckMoleculeString(smi_bad, False)
|
||||
(err, fixed_mol) = pyAvalonTools.CheckMoleculeString(smi_bad, False)
|
||||
self.assertNotEqual(err, 0)
|
||||
self.assertFalse(fixed_mol)
|
||||
pyAvalonTools.CloseCheckMolFiles()
|
||||
|
||||
# def testIsotopeBug(self):
|
||||
# mb="""D isotope problem.mol
|
||||
# Mrv0541 08141217122D
|
||||
|
||||
# 4 3 0 0 0 0 999 V2000
|
||||
# -3.2705 0.5304 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
# -2.5561 0.9429 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
# -1.8416 0.5304 0.0000 H 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
# -2.5561 1.7679 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
# 1 2 1 0 0 0 0
|
||||
# 2 3 1 0 0 0 0
|
||||
# 2 4 1 0 0 0 0
|
||||
# M ISO 1 3 2
|
||||
# M END
|
||||
# """
|
||||
# csmi = pyAvalonTools.GetCanonSmiles(mb,False)
|
||||
# self.assertEqual(csmi,'[2H]C(C)C')
|
||||
# mb="""D isotope problem.mol
|
||||
# Mrv0541 08141217122D
|
||||
# def testIsotopeBug(self):
|
||||
# mb="""D isotope problem.mol
|
||||
# Mrv0541 08141217122D
|
||||
|
||||
# 4 3 0 0 0 0 999 V2000
|
||||
# -3.2705 0.5304 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
# -2.5561 0.9429 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
# -1.8416 0.5304 0.0000 H 2 0 0 0 0 0 0 0 0 0 0 0
|
||||
# -2.5561 1.7679 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
# 1 2 1 0 0 0 0
|
||||
# 2 3 1 0 0 0 0
|
||||
# 2 4 1 0 0 0 0
|
||||
# M ISO 1 3 2
|
||||
# M END
|
||||
# """
|
||||
# csmi = pyAvalonTools.GetCanonSmiles(mb,False)
|
||||
# self.assertEqual(csmi,'[2H]C(C)C')
|
||||
# 4 3 0 0 0 0 999 V2000
|
||||
# -3.2705 0.5304 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
# -2.5561 0.9429 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
# -1.8416 0.5304 0.0000 H 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
# -2.5561 1.7679 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
# 1 2 1 0 0 0 0
|
||||
# 2 3 1 0 0 0 0
|
||||
# 2 4 1 0 0 0 0
|
||||
# M ISO 1 3 2
|
||||
# M END
|
||||
# """
|
||||
# csmi = pyAvalonTools.GetCanonSmiles(mb,False)
|
||||
# self.assertEqual(csmi,'[2H]C(C)C')
|
||||
# mb="""D isotope problem.mol
|
||||
# Mrv0541 08141217122D
|
||||
|
||||
# mb="""D isotope problem.mol
|
||||
# Mrv0541 08141217122D
|
||||
# 4 3 0 0 0 0 999 V2000
|
||||
# -3.2705 0.5304 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
# -2.5561 0.9429 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
# -1.8416 0.5304 0.0000 H 2 0 0 0 0 0 0 0 0 0 0 0
|
||||
# -2.5561 1.7679 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
# 1 2 1 0 0 0 0
|
||||
# 2 3 1 0 0 0 0
|
||||
# 2 4 1 0 0 0 0
|
||||
# M ISO 1 3 2
|
||||
# M END
|
||||
# """
|
||||
# csmi = pyAvalonTools.GetCanonSmiles(mb,False)
|
||||
# self.assertEqual(csmi,'[2H]C(C)C')
|
||||
|
||||
# 4 3 0 0 0 0 999 V2000
|
||||
# -3.2705 0.5304 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
# -2.5561 0.9429 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
# -1.8416 0.5304 0.0000 D 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
# -2.5561 1.7679 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
# 1 2 1 0 0 0 0
|
||||
# 2 3 1 0 0 0 0
|
||||
# 2 4 1 0 0 0 0
|
||||
# M END
|
||||
# """
|
||||
# csmi = pyAvalonTools.GetCanonSmiles(mb,False)
|
||||
# self.assertEqual(csmi,'[2H]C(C)C')
|
||||
|
||||
# def testChiralPBug(self):
|
||||
# mb="""Untitled Document-1
|
||||
# Mrv0541 08161213182D
|
||||
# mb="""D isotope problem.mol
|
||||
# Mrv0541 08141217122D
|
||||
|
||||
# 5 4 0 0 0 0 999 V2000
|
||||
# -1.1196 1.1491 0.0000 P 0 0 2 0 0 0 0 0 0 0 0 0
|
||||
# -0.4052 1.5616 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
# -1.9446 1.1491 0.0000 F 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
# -1.3332 1.9460 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
# -0.7071 0.4346 0.0000 Cl 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
# 1 2 1 0 0 0 0
|
||||
# 1 3 1 0 0 0 0
|
||||
# 1 4 2 0 0 0 0
|
||||
# 1 5 1 1 0 0 0
|
||||
# M END
|
||||
# """
|
||||
# r = pyAvalonTools.InitializeCheckMol(STRUCHK_INIT)
|
||||
# self.assertEqual(r, 0)
|
||||
# (err, fixed_mol) = pyAvalonTools.CheckMolecule(mb, False)
|
||||
# self.assertEqual(err, 0)
|
||||
# self.assertTrue(fixed_mol)
|
||||
# self.assertNotEqual(fixed_mol.GetAtomWithIdx(0).GetChiralTag(),Chem.rdchem.ChiralType.CHI_UNSPECIFIED)
|
||||
# 4 3 0 0 0 0 999 V2000
|
||||
# -3.2705 0.5304 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
# -2.5561 0.9429 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
# -1.8416 0.5304 0.0000 D 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
# -2.5561 1.7679 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
# 1 2 1 0 0 0 0
|
||||
# 2 3 1 0 0 0 0
|
||||
# 2 4 1 0 0 0 0
|
||||
# M END
|
||||
# """
|
||||
# csmi = pyAvalonTools.GetCanonSmiles(mb,False)
|
||||
# self.assertEqual(csmi,'[2H]C(C)C')
|
||||
|
||||
# def testChiralPBug(self):
|
||||
# mb="""Untitled Document-1
|
||||
# Mrv0541 08161213182D
|
||||
|
||||
# 5 4 0 0 0 0 999 V2000
|
||||
# -1.1196 1.1491 0.0000 P 0 0 2 0 0 0 0 0 0 0 0 0
|
||||
# -0.4052 1.5616 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
# -1.9446 1.1491 0.0000 F 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
# -1.3332 1.9460 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
# -0.7071 0.4346 0.0000 Cl 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
# 1 2 1 0 0 0 0
|
||||
# 1 3 1 0 0 0 0
|
||||
# 1 4 2 0 0 0 0
|
||||
# 1 5 1 1 0 0 0
|
||||
# M END
|
||||
# """
|
||||
# r = pyAvalonTools.InitializeCheckMol(STRUCHK_INIT)
|
||||
# self.assertEqual(r, 0)
|
||||
# (err, fixed_mol) = pyAvalonTools.CheckMolecule(mb, False)
|
||||
# self.assertEqual(err, 0)
|
||||
# self.assertTrue(fixed_mol)
|
||||
# self.assertNotEqual(fixed_mol.GetAtomWithIdx(0).GetChiralTag(),Chem.rdchem.ChiralType.CHI_UNSPECIFIED)
|
||||
|
||||
def testAvalonCountFPs(self):
|
||||
# need to go to longer bit counts to avoid collions:
|
||||
cv1 = pyAvalonTools.GetAvalonCountFP('c1ccccc1',True,nBits=6000)
|
||||
cv2 = pyAvalonTools.GetAvalonCountFP('c1ccccc1.c1ccccc1',True,nBits=6000)
|
||||
for idx,v in cv1.GetNonzeroElements().items():
|
||||
self.assertEqual(2*v,cv2[idx])
|
||||
# need to go to longer bit counts to avoid collions:
|
||||
cv1 = pyAvalonTools.GetAvalonCountFP('c1ccccc1', True, nBits=6000)
|
||||
cv2 = pyAvalonTools.GetAvalonCountFP('c1ccccc1.c1ccccc1', True, nBits=6000)
|
||||
for idx, v in cv1.GetNonzeroElements().items():
|
||||
self.assertEqual(2 * v, cv2[idx])
|
||||
|
||||
cv1 = pyAvalonTools.GetAvalonCountFP(Chem.MolFromSmiles('c1ccccc1'),nBits=6000)
|
||||
cv2 = pyAvalonTools.GetAvalonCountFP(Chem.MolFromSmiles('c1ccccc1.c1ccccc1'),nBits=6000)
|
||||
for idx,v in cv1.GetNonzeroElements().items():
|
||||
self.assertEqual(2*v,cv2[idx])
|
||||
cv1 = pyAvalonTools.GetAvalonCountFP(Chem.MolFromSmiles('c1ccccc1'), nBits=6000)
|
||||
cv2 = pyAvalonTools.GetAvalonCountFP(Chem.MolFromSmiles('c1ccccc1.c1ccccc1'), nBits=6000)
|
||||
for idx, v in cv1.GetNonzeroElements().items():
|
||||
self.assertEqual(2 * v, cv2[idx])
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
unittest.main()
|
||||
|
||||
15
External/AvalonTools/Wrap/test_list.py
vendored
15
External/AvalonTools/Wrap/test_list.py
vendored
@@ -1,15 +1,8 @@
|
||||
tests = [("python", "testAvalonTools.py", {}), ]
|
||||
|
||||
tests=[
|
||||
("python","testAvalonTools.py",{}),
|
||||
]
|
||||
|
||||
|
||||
|
||||
longTests=[]
|
||||
if __name__=='__main__':
|
||||
longTests = []
|
||||
if __name__ == '__main__':
|
||||
import sys
|
||||
from rdkit import TestRunner
|
||||
failed,tests = TestRunner.RunScript('test_list.py',0,1)
|
||||
failed, tests = TestRunner.RunScript('test_list.py', 0, 1)
|
||||
sys.exit(len(failed))
|
||||
|
||||
|
||||
|
||||
19
External/AvalonTools/test_list.py
vendored
19
External/AvalonTools/test_list.py
vendored
@@ -1,16 +1,11 @@
|
||||
tests = [
|
||||
("testExecs/test1.exe", "", {}),
|
||||
("python", "test_list.py", {"dir": "Wrap"}),
|
||||
]
|
||||
|
||||
tests=[
|
||||
("testExecs/test1.exe","",{}),
|
||||
("python","test_list.py",{"dir":"Wrap"}),
|
||||
]
|
||||
|
||||
|
||||
|
||||
longTests=[]
|
||||
if __name__=='__main__':
|
||||
longTests = []
|
||||
if __name__ == '__main__':
|
||||
import sys
|
||||
import TestRunner
|
||||
failed,tests = TestRunner.RunScript('test_list.py',0,1)
|
||||
failed, tests = TestRunner.RunScript('test_list.py', 0, 1)
|
||||
sys.exit(len(failed))
|
||||
|
||||
|
||||
|
||||
140
External/INCHI-API/python/inchi.py
vendored
140
External/INCHI-API/python/inchi.py
vendored
@@ -39,19 +39,20 @@ from rdkit import RDLogger
|
||||
logger = RDLogger.logger()
|
||||
|
||||
logLevelToLogFunctionLookup = {
|
||||
logging.INFO : logger.info,
|
||||
logging.DEBUG : logger.debug,
|
||||
logging.WARNING : logger.warning,
|
||||
logging.CRITICAL : logger.critical,
|
||||
logging.ERROR : logger.error
|
||||
}
|
||||
logging.INFO: logger.info,
|
||||
logging.DEBUG: logger.debug,
|
||||
logging.WARNING: logger.warning,
|
||||
logging.CRITICAL: logger.critical,
|
||||
logging.ERROR: logger.error
|
||||
}
|
||||
|
||||
|
||||
class InchiReadWriteError(Exception):
|
||||
pass
|
||||
pass
|
||||
|
||||
def MolFromInchi(inchi, sanitize=True, removeHs=True, logLevel=None,
|
||||
treatWarningAsError=False):
|
||||
"""Construct a molecule from a InChI string
|
||||
|
||||
def MolFromInchi(inchi, sanitize=True, removeHs=True, logLevel=None, treatWarningAsError=False):
|
||||
"""Construct a molecule from a InChI string
|
||||
|
||||
Keyword arguments:
|
||||
sanitize -- set to True to enable sanitization of the molecule. Default is
|
||||
@@ -67,31 +68,31 @@ def MolFromInchi(inchi, sanitize=True, removeHs=True, logLevel=None,
|
||||
Returns:
|
||||
a rdkit.Chem.rdchem.Mol instance
|
||||
"""
|
||||
try:
|
||||
mol, retcode, message, log = rdinchi.InchiToMol(inchi, sanitize, removeHs)
|
||||
except ValueError as e :
|
||||
logger.error(str(e))
|
||||
return None
|
||||
try:
|
||||
mol, retcode, message, log = rdinchi.InchiToMol(inchi, sanitize, removeHs)
|
||||
except ValueError as e:
|
||||
logger.error(str(e))
|
||||
return None
|
||||
|
||||
if logLevel is not None:
|
||||
if logLevel not in logLevelToLogFunctionLookup:
|
||||
raise ValueError("Unsupported log level: %d" % logLevel)
|
||||
log = logLevelToLogFunctionLookup[logLevel]
|
||||
if retcode == 0:
|
||||
log(message)
|
||||
if logLevel is not None:
|
||||
if logLevel not in logLevelToLogFunctionLookup:
|
||||
raise ValueError("Unsupported log level: %d" % logLevel)
|
||||
log = logLevelToLogFunctionLookup[logLevel]
|
||||
if retcode == 0:
|
||||
log(message)
|
||||
|
||||
if retcode != 0:
|
||||
if retcode == 1:
|
||||
logger.warning(message)
|
||||
else:
|
||||
logger.error(message)
|
||||
if treatWarningAsError and retcode != 0:
|
||||
raise InchiReadWriteError(mol, message)
|
||||
return mol
|
||||
if retcode != 0:
|
||||
if retcode == 1:
|
||||
logger.warning(message)
|
||||
else:
|
||||
logger.error(message)
|
||||
if treatWarningAsError and retcode != 0:
|
||||
raise InchiReadWriteError(mol, message)
|
||||
return mol
|
||||
|
||||
def MolToInchiAndAuxInfo(mol, options="", logLevel=None,
|
||||
treatWarningAsError=False):
|
||||
"""Returns the standard InChI string and InChI auxInfo for a molecule
|
||||
|
||||
def MolToInchiAndAuxInfo(mol, options="", logLevel=None, treatWarningAsError=False):
|
||||
"""Returns the standard InChI string and InChI auxInfo for a molecule
|
||||
|
||||
Keyword arguments:
|
||||
logLevel -- the log level used for logging logs and messages from InChI
|
||||
@@ -105,25 +106,26 @@ def MolToInchiAndAuxInfo(mol, options="", logLevel=None,
|
||||
a tuple of the standard InChI string and the auxInfo string returned by
|
||||
InChI API, in that order, for the input molecule
|
||||
"""
|
||||
inchi, retcode, message, logs, aux = rdinchi.MolToInchi(mol, options)
|
||||
if logLevel is not None:
|
||||
if logLevel not in logLevelToLogFunctionLookup:
|
||||
raise ValueError("Unsupported log level: %d" % logLevel)
|
||||
log = logLevelToLogFunctionLookup[logLevel]
|
||||
if retcode == 0:
|
||||
log(message)
|
||||
if retcode != 0:
|
||||
if retcode == 1:
|
||||
logger.warning(message)
|
||||
else:
|
||||
logger.error(message)
|
||||
inchi, retcode, message, logs, aux = rdinchi.MolToInchi(mol, options)
|
||||
if logLevel is not None:
|
||||
if logLevel not in logLevelToLogFunctionLookup:
|
||||
raise ValueError("Unsupported log level: %d" % logLevel)
|
||||
log = logLevelToLogFunctionLookup[logLevel]
|
||||
if retcode == 0:
|
||||
log(message)
|
||||
if retcode != 0:
|
||||
if retcode == 1:
|
||||
logger.warning(message)
|
||||
else:
|
||||
logger.error(message)
|
||||
|
||||
if treatWarningAsError and retcode != 0:
|
||||
raise InchiReadWriteError(inchi, aux, message)
|
||||
return inchi, aux
|
||||
|
||||
if treatWarningAsError and retcode != 0:
|
||||
raise InchiReadWriteError(inchi, aux, message)
|
||||
return inchi, aux
|
||||
|
||||
def MolToInchi(mol, options="", logLevel=None, treatWarningAsError=False):
|
||||
"""Returns the standard InChI string for a molecule
|
||||
"""Returns the standard InChI string for a molecule
|
||||
|
||||
Keyword arguments:
|
||||
logLevel -- the log level used for logging logs and messages from InChI
|
||||
@@ -136,25 +138,29 @@ def MolToInchi(mol, options="", logLevel=None, treatWarningAsError=False):
|
||||
Returns:
|
||||
the standard InChI string returned by InChI API for the input molecule
|
||||
"""
|
||||
if options.find('AuxNone')==-1:
|
||||
if options:
|
||||
options += " /AuxNone"
|
||||
else:
|
||||
options += "/AuxNone"
|
||||
|
||||
try:
|
||||
inchi, aux = MolToInchiAndAuxInfo(mol, options, logLevel=logLevel,
|
||||
treatWarningAsError=treatWarningAsError)
|
||||
except InchiReadWriteError as inst:
|
||||
inchi, aux, message = inst.args
|
||||
raise InchiReadWriteError(inchi, message)
|
||||
return inchi
|
||||
if options.find('AuxNone') == -1:
|
||||
if options:
|
||||
options += " /AuxNone"
|
||||
else:
|
||||
options += "/AuxNone"
|
||||
|
||||
try:
|
||||
inchi, aux = MolToInchiAndAuxInfo(mol, options, logLevel=logLevel,
|
||||
treatWarningAsError=treatWarningAsError)
|
||||
except InchiReadWriteError as inst:
|
||||
inchi, aux, message = inst.args
|
||||
raise InchiReadWriteError(inchi, message)
|
||||
return inchi
|
||||
|
||||
|
||||
def InchiToInchiKey(inchi):
|
||||
"""Return the InChI key for the given InChI string. Return None on error"""
|
||||
ret = rdinchi.InchiToInchiKey(inchi)
|
||||
if ret: return ret
|
||||
else: return None
|
||||
"""Return the InChI key for the given InChI string. Return None on error"""
|
||||
ret = rdinchi.InchiToInchiKey(inchi)
|
||||
if ret:
|
||||
return ret
|
||||
else:
|
||||
return None
|
||||
|
||||
__all__ = ['MolToInchiAndAuxInfo', 'MolToInchi', 'MolFromInchi',
|
||||
'InchiReadWriteError', 'InchiToInchiKey', 'INCHI_AVAILABLE']
|
||||
|
||||
__all__ = ['MolToInchiAndAuxInfo', 'MolToInchi', 'MolFromInchi', 'InchiReadWriteError',
|
||||
'InchiToInchiKey', 'INCHI_AVAILABLE']
|
||||
|
||||
400
External/pymol/modules/pymol/rpc.py
vendored
400
External/pymol/modules/pymol/rpc.py
vendored
@@ -15,13 +15,15 @@
|
||||
"""
|
||||
from __future__ import print_function
|
||||
import SimpleXMLRPCServer
|
||||
import threading,sys,time,types,os,tempfile
|
||||
from pymol import cmd,cgo
|
||||
|
||||
import threading, sys, time, types, os, tempfile
|
||||
from pymol import cmd, cgo
|
||||
|
||||
# initial port to try for the server
|
||||
_xmlPort=9123
|
||||
_xmlPort = 9123
|
||||
# number of alternate ports to try if the first fails
|
||||
_nPortsToTry=5
|
||||
_nPortsToTry = 5
|
||||
|
||||
|
||||
def rpcCmd(cmdText):
|
||||
""" executes a PyMol API command
|
||||
|
||||
@@ -33,42 +35,46 @@ def rpcCmd(cmdText):
|
||||
return res
|
||||
else:
|
||||
return ''
|
||||
|
||||
|
||||
|
||||
def rpcQuit():
|
||||
""" causes PyMol to quit """
|
||||
cmd.quit()
|
||||
return 1
|
||||
|
||||
|
||||
|
||||
def rpcZoom(what=''):
|
||||
""" executes cmd.zoom(what) """
|
||||
cmd.zoom(what)
|
||||
return 1
|
||||
|
||||
|
||||
def rpcSet(prop,val,obj):
|
||||
|
||||
|
||||
def rpcSet(prop, val, obj):
|
||||
""" executes a PyMol set command
|
||||
|
||||
return value is either the result of the command or the empty string
|
||||
|
||||
"""
|
||||
res = cmd.set(prop,val,obj)
|
||||
res = cmd.set(prop, val, obj)
|
||||
if res is not None:
|
||||
return res
|
||||
else:
|
||||
return ''
|
||||
|
||||
def rpcGet(prop,obj):
|
||||
|
||||
|
||||
def rpcGet(prop, obj):
|
||||
""" executes a PyMol get command
|
||||
|
||||
return value is either the result of the command or the empty string
|
||||
|
||||
"""
|
||||
res = cmd.get(prop,obj)
|
||||
res = cmd.get(prop, obj)
|
||||
if res is not None:
|
||||
return res
|
||||
else:
|
||||
return ''
|
||||
|
||||
|
||||
|
||||
def rpcPing():
|
||||
""" Used to establish whether or not the server is alive.
|
||||
|
||||
@@ -79,8 +85,9 @@ def rpcPing():
|
||||
|
||||
"""
|
||||
return 1
|
||||
|
||||
def rpcLabel(pos,labelText,id='lab1',color=(1,1,1)):
|
||||
|
||||
|
||||
def rpcLabel(pos, labelText, id='lab1', color=(1, 1, 1)):
|
||||
""" create a text label
|
||||
|
||||
Arguments:
|
||||
@@ -93,37 +100,38 @@ def rpcLabel(pos,labelText,id='lab1',color=(1,1,1)):
|
||||
at the moment this is, how you say, a hack
|
||||
|
||||
"""
|
||||
x,y,z = pos
|
||||
text="""
|
||||
x, y, z = pos
|
||||
text = """
|
||||
Atom
|
||||
|
||||
1 0 0 0 0 0 0 0 0 0999 V2000
|
||||
% 10.4f% 10.4f%10.4f C 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
M END"""%(x,y,z)
|
||||
cmd.read_molstr(text,id)
|
||||
cmd.label("%s"%(id),'"%s"'%labelText)
|
||||
cmd.hide("nonbonded",id)
|
||||
cmd.set_color("%s-color"%id,color)
|
||||
cmd.color("%s-color"%id,id)
|
||||
M END""" % (x, y, z)
|
||||
cmd.read_molstr(text, id)
|
||||
cmd.label("%s" % (id), '"%s"' % labelText)
|
||||
cmd.hide("nonbonded", id)
|
||||
cmd.set_color("%s-color" % id, color)
|
||||
cmd.color("%s-color" % id, id)
|
||||
return 1
|
||||
|
||||
|
||||
|
||||
def rpcResetCGO(id):
|
||||
""" removes a CGO from the local dictionary
|
||||
|
||||
"""
|
||||
global cgoDict
|
||||
if id=="*":
|
||||
cgoDict={}
|
||||
if id == "*":
|
||||
cgoDict = {}
|
||||
res = 1
|
||||
elif cgoDict.has_key(id):
|
||||
del(cgoDict[id])
|
||||
del (cgoDict[id])
|
||||
res = 1
|
||||
else:
|
||||
res = 0
|
||||
return res
|
||||
|
||||
def rpcSphere(pos,rad,color,id='cgo',extend=1,
|
||||
transparent=0,transparency=0.5):
|
||||
|
||||
|
||||
def rpcSphere(pos, rad, color, id='cgo', extend=1, transparent=0, transparency=0.5):
|
||||
""" create a sphere
|
||||
|
||||
Arguments:
|
||||
@@ -137,24 +145,24 @@ def rpcSphere(pos,rad,color,id='cgo',extend=1,
|
||||
transparent: (OPTIONAL) sets the object to be transparent
|
||||
transparency: (OPTIONAL) the percent transparency of the object
|
||||
"""
|
||||
r,g,b = color
|
||||
x,y,z = pos
|
||||
r, g, b = color
|
||||
x, y, z = pos
|
||||
if extend:
|
||||
obj = cgoDict.get(id,[])
|
||||
obj = cgoDict.get(id, [])
|
||||
else:
|
||||
obj = []
|
||||
if not transparent:
|
||||
o = []
|
||||
else:
|
||||
o = [cgo.ALPHA,1-transparency]
|
||||
o.extend([cgo.COLOR,r,g,b,cgo.SPHERE,x,y,z,rad])
|
||||
o = [cgo.ALPHA, 1 - transparency]
|
||||
o.extend([cgo.COLOR, r, g, b, cgo.SPHERE, x, y, z, rad])
|
||||
obj.extend(o)
|
||||
cgoDict[id] = obj
|
||||
cmd.load_cgo(obj,id,1)
|
||||
cmd.load_cgo(obj, id, 1)
|
||||
return 1
|
||||
|
||||
def rpcRenderCGO(cgoV,id='cgo',extend=1):
|
||||
|
||||
def rpcRenderCGO(cgoV, id='cgo', extend=1):
|
||||
""" renders a CGO vector
|
||||
|
||||
Arguments:
|
||||
@@ -165,15 +173,15 @@ def rpcRenderCGO(cgoV,id='cgo',extend=1):
|
||||
to the ojbect
|
||||
"""
|
||||
if extend:
|
||||
obj = cgoDict.get(id,[])
|
||||
obj = cgoDict.get(id, [])
|
||||
else:
|
||||
obj = []
|
||||
obj.extend(cgoV)
|
||||
cmd.load_cgo(obj,id,1)
|
||||
cmd.load_cgo(obj, id, 1)
|
||||
return 1
|
||||
|
||||
|
||||
def rpcSpheres(sphereD,id='cgo',extend=1):
|
||||
|
||||
def rpcSpheres(sphereD, id='cgo', extend=1):
|
||||
""" create a sphere
|
||||
|
||||
Arguments:
|
||||
@@ -184,24 +192,25 @@ def rpcSpheres(sphereD,id='cgo',extend=1):
|
||||
to the ojbect
|
||||
"""
|
||||
if extend:
|
||||
obj = cgoDict.get(id,[])
|
||||
obj = cgoDict.get(id, [])
|
||||
else:
|
||||
obj = []
|
||||
for pos,rad,color,transparent,transparency in sphereD:
|
||||
r,g,b = color
|
||||
x,y,z = pos
|
||||
for pos, rad, color, transparent, transparency in sphereD:
|
||||
r, g, b = color
|
||||
x, y, z = pos
|
||||
if not transparent:
|
||||
o = []
|
||||
else:
|
||||
o = [cgo.ALPHA,1-transparency]
|
||||
o.extend([cgo.COLOR,r,g,b,cgo.SPHERE,x,y,z,rad])
|
||||
o = [cgo.ALPHA, 1 - transparency]
|
||||
o.extend([cgo.COLOR, r, g, b, cgo.SPHERE, x, y, z, rad])
|
||||
obj.extend(o)
|
||||
cgoDict[id] = obj
|
||||
cmd.load_cgo(obj,id,1)
|
||||
cmd.load_cgo(obj, id, 1)
|
||||
return 1
|
||||
|
||||
def rpcCylinder(end1,end2,rad,color1,id='cgo',color2=None,extend=1,
|
||||
transparent=0,transparency=0.5):
|
||||
|
||||
|
||||
def rpcCylinder(end1, end2, rad, color1, id='cgo', color2=None, extend=1, transparent=0,
|
||||
transparency=0.5):
|
||||
""" create a cylinder
|
||||
|
||||
Arguments:
|
||||
@@ -224,31 +233,46 @@ is white
|
||||
|
||||
"""
|
||||
global cgoDict
|
||||
|
||||
if color2 is None: color2 = color1
|
||||
r1,g1,b1 = color1
|
||||
r2,g2,b2 = color2
|
||||
x1,y1,z1 = end1
|
||||
x2,y2,z2 = end2
|
||||
|
||||
if color2 is None:
|
||||
color2 = color1
|
||||
r1, g1, b1 = color1
|
||||
r2, g2, b2 = color2
|
||||
x1, y1, z1 = end1
|
||||
x2, y2, z2 = end2
|
||||
if extend:
|
||||
obj = cgoDict.get(id,[])
|
||||
obj = cgoDict.get(id, [])
|
||||
else:
|
||||
obj = []
|
||||
if not transparent:
|
||||
o = []
|
||||
else:
|
||||
o = [cgo.ALPHA,1-transparency]
|
||||
o.extend([cgo.CYLINDER,x1,y1,z1,x2,y2,z2,rad,r1,g1,b1,r2,g2,b2,])
|
||||
o = [cgo.ALPHA, 1 - transparency]
|
||||
o.extend([cgo.CYLINDER,
|
||||
x1,
|
||||
y1,
|
||||
z1,
|
||||
x2,
|
||||
y2,
|
||||
z2,
|
||||
rad,
|
||||
r1,
|
||||
g1,
|
||||
b1,
|
||||
r2,
|
||||
g2,
|
||||
b2, ])
|
||||
obj.extend(o)
|
||||
cgoDict[id] = obj
|
||||
cmd.load_cgo(obj,id,1)
|
||||
cmd.load_cgo(obj, id, 1)
|
||||
return 1
|
||||
|
||||
|
||||
|
||||
def rpcShow(objs):
|
||||
""" shows (enables) an object (or objects)"""
|
||||
if type(objs) not in (types.ListType,types.TupleType):
|
||||
objs = (objs,)
|
||||
|
||||
if type(objs) not in (types.ListType, types.TupleType):
|
||||
objs = (objs, )
|
||||
|
||||
for objName in objs:
|
||||
try:
|
||||
cmd.enable(objName)
|
||||
@@ -257,13 +281,14 @@ def rpcShow(objs):
|
||||
break
|
||||
else:
|
||||
res = 1
|
||||
return res
|
||||
|
||||
return res
|
||||
|
||||
|
||||
def rpcHide(objs):
|
||||
""" hides (disables) an object (or objects) """
|
||||
if type(objs) not in (types.ListType,types.TupleType):
|
||||
objs = (objs,)
|
||||
|
||||
if type(objs) not in (types.ListType, types.TupleType):
|
||||
objs = (objs, )
|
||||
|
||||
for objName in objs:
|
||||
try:
|
||||
cmd.disable(objName)
|
||||
@@ -272,8 +297,9 @@ def rpcHide(objs):
|
||||
break
|
||||
else:
|
||||
res = 1
|
||||
return res
|
||||
|
||||
return res
|
||||
|
||||
|
||||
def rpcDeleteObject(objName):
|
||||
""" deletes an object """
|
||||
try:
|
||||
@@ -282,8 +308,9 @@ def rpcDeleteObject(objName):
|
||||
res = 0
|
||||
else:
|
||||
res = 1
|
||||
return res
|
||||
|
||||
return res
|
||||
|
||||
|
||||
def rpcDeleteAll():
|
||||
""" deletes all objects """
|
||||
res = cmd.delete('all')
|
||||
@@ -291,8 +318,9 @@ def rpcDeleteAll():
|
||||
return res
|
||||
else:
|
||||
return ''
|
||||
|
||||
def colorObj(objName,colorScheme):
|
||||
|
||||
|
||||
def colorObj(objName, colorScheme):
|
||||
""" sets an molecule's color scheme
|
||||
Arguments:
|
||||
- objName: the object (molecule) to change
|
||||
@@ -304,21 +332,22 @@ def colorObj(objName,colorScheme):
|
||||
if colorScheme == 'std':
|
||||
# this is an adaptation of the cbag scheme from util.py, but
|
||||
# with a gray carbon.
|
||||
cmd.color("magenta","("+objName+")",quiet=1)
|
||||
cmd.color("oxygen","(elem O and "+objName+")",quiet=1)
|
||||
cmd.color("nitrogen","(elem N and "+objName+")",quiet=1)
|
||||
cmd.color("sulfur","(elem S and "+objName+")",quiet=1)
|
||||
cmd.color("hydrogen","(elem H and "+objName+")",quiet=1)
|
||||
cmd.color("gray","(elem C and "+objName+")",quiet=1)
|
||||
elif hasattr(utils,colorScheme):
|
||||
fn = getattr(utils,colorScheme)
|
||||
fn(objName,quiet=1)
|
||||
cmd.color("magenta", "(" + objName + ")", quiet=1)
|
||||
cmd.color("oxygen", "(elem O and " + objName + ")", quiet=1)
|
||||
cmd.color("nitrogen", "(elem N and " + objName + ")", quiet=1)
|
||||
cmd.color("sulfur", "(elem S and " + objName + ")", quiet=1)
|
||||
cmd.color("hydrogen", "(elem H and " + objName + ")", quiet=1)
|
||||
cmd.color("gray", "(elem C and " + objName + ")", quiet=1)
|
||||
elif hasattr(utils, colorScheme):
|
||||
fn = getattr(utils, colorScheme)
|
||||
fn(objName, quiet=1)
|
||||
res = 1
|
||||
else:
|
||||
res = 0
|
||||
return res
|
||||
|
||||
def rpcLoadPDB(data,objName,colorScheme='',replace=1):
|
||||
|
||||
|
||||
def rpcLoadPDB(data, objName, colorScheme='', replace=1):
|
||||
""" loads a molecule from a pdb string
|
||||
|
||||
Arguments:
|
||||
@@ -335,15 +364,15 @@ def rpcLoadPDB(data,objName,colorScheme='',replace=1):
|
||||
from pymol import util
|
||||
if replace:
|
||||
cmd.delete(objName)
|
||||
res = cmd.read_pdbstr(data,objName)
|
||||
colorObj(objName,colorScheme)
|
||||
res = cmd.read_pdbstr(data, objName)
|
||||
colorObj(objName, colorScheme)
|
||||
if res is not None:
|
||||
return res
|
||||
else:
|
||||
return ''
|
||||
|
||||
|
||||
def rpcLoadMolBlock(data,objName,colorScheme='',replace=1):
|
||||
|
||||
def rpcLoadMolBlock(data, objName, colorScheme='', replace=1):
|
||||
""" loads a molecule from a mol block
|
||||
|
||||
Arguments:
|
||||
@@ -359,15 +388,15 @@ def rpcLoadMolBlock(data,objName,colorScheme='',replace=1):
|
||||
from pymol import util
|
||||
if replace:
|
||||
cmd.delete(objName)
|
||||
res = cmd.read_molstr(data,objName)
|
||||
colorObj(objName,colorScheme)
|
||||
res = cmd.read_molstr(data, objName)
|
||||
colorObj(objName, colorScheme)
|
||||
if res is not None:
|
||||
return res
|
||||
else:
|
||||
return ''
|
||||
|
||||
|
||||
def rpcLoadFile(fileName,objName='',format='',colorScheme='',replace=1):
|
||||
|
||||
def rpcLoadFile(fileName, objName='', format='', colorScheme='', replace=1):
|
||||
""" loads an object from a file
|
||||
|
||||
Arguments:
|
||||
@@ -384,15 +413,15 @@ def rpcLoadFile(fileName,objName='',format='',colorScheme='',replace=1):
|
||||
objName = fileName.split('.')[0]
|
||||
if replace:
|
||||
cmd.delete(objName)
|
||||
res = cmd.load(fileName,objName,format=format)
|
||||
colorObj(objName,colorScheme)
|
||||
res = cmd.load(fileName, objName, format=format)
|
||||
colorObj(objName, colorScheme)
|
||||
if res is not None:
|
||||
return res
|
||||
else:
|
||||
return ''
|
||||
|
||||
|
||||
def rpcLoadSurface(fileName,objName,format='',surfaceLevel=1.0):
|
||||
|
||||
def rpcLoadSurface(fileName, objName, format='', surfaceLevel=1.0):
|
||||
""" loads surface data from a file and adds an isosurface
|
||||
|
||||
Arguments:
|
||||
@@ -401,18 +430,19 @@ def rpcLoadSurface(fileName,objName,format='',surfaceLevel=1.0):
|
||||
format: (OPTIONAL) the format of the input file
|
||||
surfaceLevel: (OPTIONAL) the isosurface level
|
||||
|
||||
"""
|
||||
"""
|
||||
if not objName:
|
||||
objName = fileName.split('.')[0]
|
||||
gridName = 'grid-%s'%objName
|
||||
res = cmd.load(fileName,gridName,format='')
|
||||
cmd.isosurface(objName,gridName,level=surfaceLevel)
|
||||
gridName = 'grid-%s' % objName
|
||||
res = cmd.load(fileName, gridName, format='')
|
||||
cmd.isosurface(objName, gridName, level=surfaceLevel)
|
||||
if res is not None:
|
||||
return res
|
||||
else:
|
||||
return ''
|
||||
|
||||
def rpcLoadSurfaceData(data,objName='surface',format='',surfaceLevel=1.0):
|
||||
|
||||
|
||||
def rpcLoadSurfaceData(data, objName='surface', format='', surfaceLevel=1.0):
|
||||
""" loads surface data from a string and adds an isosurface
|
||||
|
||||
Arguments:
|
||||
@@ -421,21 +451,21 @@ def rpcLoadSurfaceData(data,objName='surface',format='',surfaceLevel=1.0):
|
||||
format: (OPTIONAL) the format of the input file
|
||||
surfaceLevel: (OPTIONAL) the isosurface level
|
||||
|
||||
"""
|
||||
gridName = 'grid-%s'%objName
|
||||
"""
|
||||
gridName = 'grid-%s' % objName
|
||||
# it would be nice if we didn't have to go by way of the temporary file,
|
||||
# but at the moment pymol will only read shapes from files
|
||||
tempnm = tempfile.mktemp('.grd')
|
||||
open(tempnm,'w+').write(data)
|
||||
res = rpcLoadSurface(tempnm,objName,format='',surfaceLevel=surfaceLevel)
|
||||
open(tempnm, 'w+').write(data)
|
||||
res = rpcLoadSurface(tempnm, objName, format='', surfaceLevel=surfaceLevel)
|
||||
os.unlink(tempnm)
|
||||
if res is not None:
|
||||
return res
|
||||
else:
|
||||
return ''
|
||||
|
||||
|
||||
def rpcSave(filename,objName='all',state=0,format=''):
|
||||
|
||||
def rpcSave(filename, objName='all', state=0, format=''):
|
||||
""" executes a cmd.save command
|
||||
|
||||
Arguments:
|
||||
@@ -445,14 +475,14 @@ def rpcSave(filename,objName='all',state=0,format=''):
|
||||
- format: (OPTIONAL) output format
|
||||
|
||||
"""
|
||||
res = cmd.save(filename,objName,state,format)
|
||||
res = cmd.save(filename, objName, state, format)
|
||||
if res is not None:
|
||||
return res
|
||||
else:
|
||||
return ''
|
||||
|
||||
|
||||
def rpcRotate(vect,objName='',state=-1):
|
||||
|
||||
def rpcRotate(vect, objName='', state=-1):
|
||||
""" rotates objects
|
||||
|
||||
Arguments:
|
||||
@@ -462,12 +492,13 @@ def rpcRotate(vect,objName='',state=-1):
|
||||
if -1 (the default), all states are rotated
|
||||
|
||||
"""
|
||||
cmd.rotate('x',vect[0],objName,state=state)
|
||||
cmd.rotate('y',vect[1],objName,state=state)
|
||||
cmd.rotate('z',vect[2],objName,state=state)
|
||||
cmd.rotate('x', vect[0], objName, state=state)
|
||||
cmd.rotate('y', vect[1], objName, state=state)
|
||||
cmd.rotate('z', vect[2], objName, state=state)
|
||||
return 1
|
||||
|
||||
def rpcTranslate(vect,objName='all',state=-1):
|
||||
|
||||
def rpcTranslate(vect, objName='all', state=-1):
|
||||
""" translates objects
|
||||
|
||||
Arguments:
|
||||
@@ -476,34 +507,40 @@ def rpcTranslate(vect,objName='all',state=-1):
|
||||
- state: (OPTIONAL) if zero only visible states are translated,
|
||||
if -1 (the default), all states are translated
|
||||
"""
|
||||
cmd.translate(vect,objNAme,state=state)
|
||||
cmd.translate(vect, objNAme, state=state)
|
||||
return 1
|
||||
|
||||
def rpcGetNames(what='selections',enabledOnly=1):
|
||||
|
||||
def rpcGetNames(what='selections', enabledOnly=1):
|
||||
""" returns the results of cmd.get_names(what) """
|
||||
return cmd.get_names(what,enabled_only=enabledOnly)
|
||||
|
||||
def rpcIdentify(what='all',mode=0):
|
||||
return cmd.get_names(what, enabled_only=enabledOnly)
|
||||
|
||||
|
||||
def rpcIdentify(what='all', mode=0):
|
||||
""" returns the results of cmd.identify(what,mode) """
|
||||
return cmd.identify(what,mode=mode)
|
||||
|
||||
return cmd.identify(what, mode=mode)
|
||||
|
||||
|
||||
def rpcIndex(what='all'):
|
||||
""" returns the results of cmd.index(what) """
|
||||
return cmd.index(what)
|
||||
|
||||
|
||||
|
||||
def rpcCountAtoms(what='all'):
|
||||
""" returns the results of cmd.count_atoms(what) """
|
||||
return cmd.count_atoms(what)
|
||||
|
||||
def rpcIdAtom(what='all',mode=0):
|
||||
|
||||
|
||||
def rpcIdAtom(what='all', mode=0):
|
||||
""" returns the results of cmd.id_atom(what) """
|
||||
return cmd.id_atom(what,mode=mode)
|
||||
|
||||
def rpcGetAtomCoords(what='all',state=0):
|
||||
return cmd.id_atom(what, mode=mode)
|
||||
|
||||
|
||||
def rpcGetAtomCoords(what='all', state=0):
|
||||
""" returns the results of cmd.get_atom_coords(what,state) """
|
||||
return cmd.get_atom_coords(what,state=state)
|
||||
|
||||
|
||||
return cmd.get_atom_coords(what, state=state)
|
||||
|
||||
|
||||
def rpcHelp(what=''):
|
||||
""" returns general help text or help on a particular command """
|
||||
global serv
|
||||
@@ -514,7 +551,7 @@ def rpcHelp(what=''):
|
||||
funcs = serv.funcs
|
||||
if funcs.has_key(what):
|
||||
fn = funcs[what]
|
||||
res = "Function: %s("%what
|
||||
res = "Function: %s(" % what
|
||||
defs = fn.func_defaults
|
||||
if defs:
|
||||
code = fn.func_code
|
||||
@@ -524,16 +561,16 @@ def rpcHelp(what=''):
|
||||
for i in range(code.co_argcount - nDefs):
|
||||
args.append(code.co_varnames[i])
|
||||
for j in range(nDefs):
|
||||
vName = code.co_varnames[j+i+1]
|
||||
args.append("%s=%s"%(vName,repr(defs[j])))
|
||||
vName = code.co_varnames[j + i + 1]
|
||||
args.append("%s=%s" % (vName, repr(defs[j])))
|
||||
res += ','.join(args)
|
||||
res += ')\n'
|
||||
if fn.func_doc:
|
||||
res += fn.func_doc
|
||||
return res
|
||||
|
||||
|
||||
def launch_XMLRPC(hostname='',port=_xmlPort,nToTry=_nPortsToTry):
|
||||
return res
|
||||
|
||||
|
||||
def launch_XMLRPC(hostname='', port=_xmlPort, nToTry=_nPortsToTry):
|
||||
""" launches the xmlrpc server into a separate thread
|
||||
|
||||
Arguments:
|
||||
@@ -546,59 +583,58 @@ def launch_XMLRPC(hostname='',port=_xmlPort,nToTry=_nPortsToTry):
|
||||
"""
|
||||
if not hostname:
|
||||
import os
|
||||
hostname = os.environ.get('PYMOL_RPCHOST','')
|
||||
if not hostname or hostname.upper()=='LOCALHOST':
|
||||
hostname = os.environ.get('PYMOL_RPCHOST', '')
|
||||
if not hostname or hostname.upper() == 'LOCALHOST':
|
||||
hostname = 'localhost'
|
||||
else:
|
||||
import socket
|
||||
hostname=socket.gethostbyname(socket.gethostname())
|
||||
|
||||
global cgoDict,serv
|
||||
hostname = socket.gethostbyname(socket.gethostname())
|
||||
|
||||
global cgoDict, serv
|
||||
cgoDict = {}
|
||||
for i in range(nToTry):
|
||||
try:
|
||||
serv = SimpleXMLRPCServer.SimpleXMLRPCServer((hostname,port+i),logRequests=0)
|
||||
serv = SimpleXMLRPCServer.SimpleXMLRPCServer((hostname, port + i), logRequests=0)
|
||||
except Exception:
|
||||
serv = None
|
||||
else:
|
||||
break
|
||||
if serv:
|
||||
print('xml-rpc server running on host %s, port %d'%(hostname,port+i))
|
||||
serv.register_function(rpcCmd,'do')
|
||||
serv.register_function(rpcQuit,'quit')
|
||||
serv.register_function(rpcSet,'set')
|
||||
serv.register_function(rpcGet,'get')
|
||||
serv.register_function(rpcPing,'ping')
|
||||
serv.register_function(rpcResetCGO,'resetCGO')
|
||||
serv.register_function(rpcRenderCGO,'renderCGO')
|
||||
serv.register_function(rpcSphere,'sphere')
|
||||
serv.register_function(rpcSpheres,'spheres')
|
||||
serv.register_function(rpcCylinder,'cylinder')
|
||||
serv.register_function(rpcHide,'hide')
|
||||
serv.register_function(rpcShow,'show')
|
||||
serv.register_function(rpcZoom,'zoom')
|
||||
serv.register_function(rpcDeleteObject,'deleteObject')
|
||||
serv.register_function(rpcDeleteAll,'deleteAll')
|
||||
serv.register_function(rpcLoadPDB,'loadPDB')
|
||||
serv.register_function(rpcLoadMolBlock,'loadMolBlock')
|
||||
serv.register_function(rpcLoadSurface,'loadSurface')
|
||||
serv.register_function(rpcLoadSurfaceData,'loadSurfaceData')
|
||||
serv.register_function(rpcLoadFile,'loadFile')
|
||||
serv.register_function(rpcSave,'save')
|
||||
serv.register_function(rpcLabel,'label')
|
||||
serv.register_function(rpcRotate,'rotate')
|
||||
serv.register_function(rpcTranslate,'translate')
|
||||
serv.register_function(rpcGetNames,'getNames')
|
||||
serv.register_function(rpcIdentify,'identify')
|
||||
serv.register_function(rpcIndex,'index')
|
||||
serv.register_function(rpcCountAtoms,'countAtoms')
|
||||
serv.register_function(rpcIdAtom,'idAtom')
|
||||
serv.register_function(rpcHelp,'help')
|
||||
serv.register_function(rpcGetAtomCoords,'getAtomCoords')
|
||||
print('xml-rpc server running on host %s, port %d' % (hostname, port + i))
|
||||
serv.register_function(rpcCmd, 'do')
|
||||
serv.register_function(rpcQuit, 'quit')
|
||||
serv.register_function(rpcSet, 'set')
|
||||
serv.register_function(rpcGet, 'get')
|
||||
serv.register_function(rpcPing, 'ping')
|
||||
serv.register_function(rpcResetCGO, 'resetCGO')
|
||||
serv.register_function(rpcRenderCGO, 'renderCGO')
|
||||
serv.register_function(rpcSphere, 'sphere')
|
||||
serv.register_function(rpcSpheres, 'spheres')
|
||||
serv.register_function(rpcCylinder, 'cylinder')
|
||||
serv.register_function(rpcHide, 'hide')
|
||||
serv.register_function(rpcShow, 'show')
|
||||
serv.register_function(rpcZoom, 'zoom')
|
||||
serv.register_function(rpcDeleteObject, 'deleteObject')
|
||||
serv.register_function(rpcDeleteAll, 'deleteAll')
|
||||
serv.register_function(rpcLoadPDB, 'loadPDB')
|
||||
serv.register_function(rpcLoadMolBlock, 'loadMolBlock')
|
||||
serv.register_function(rpcLoadSurface, 'loadSurface')
|
||||
serv.register_function(rpcLoadSurfaceData, 'loadSurfaceData')
|
||||
serv.register_function(rpcLoadFile, 'loadFile')
|
||||
serv.register_function(rpcSave, 'save')
|
||||
serv.register_function(rpcLabel, 'label')
|
||||
serv.register_function(rpcRotate, 'rotate')
|
||||
serv.register_function(rpcTranslate, 'translate')
|
||||
serv.register_function(rpcGetNames, 'getNames')
|
||||
serv.register_function(rpcIdentify, 'identify')
|
||||
serv.register_function(rpcIndex, 'index')
|
||||
serv.register_function(rpcCountAtoms, 'countAtoms')
|
||||
serv.register_function(rpcIdAtom, 'idAtom')
|
||||
serv.register_function(rpcHelp, 'help')
|
||||
serv.register_function(rpcGetAtomCoords, 'getAtomCoords')
|
||||
serv.register_introspection_functions()
|
||||
t = threading.Thread(target=serv.serve_forever)
|
||||
t.setDaemon(1)
|
||||
t.start()
|
||||
else:
|
||||
print('xml-rpc server could not be started')
|
||||
|
||||
|
||||
Reference in New Issue
Block a user