コード例 #1
0
ファイル: testpcjsonformat.py プロジェクト: yueli9/openbabel
 def test_write_stereo_cistrans(self):
     """Test writing cis-trans stereochemistry."""
     # (Superfluous?) parity value is not set to same/opposite (1/2). unknown (255) is valid though.
     # Cis
     mols = list(
         pybel.readfile("pcjson", os.path.join(filedir,
                                               'CID_643833_2D.json')))
     output = json.loads(mols[0].write('pcjson'))
     self.assertEqual(output['PC_Compounds'][0]['stereo'], [{
         'planar': {
             'type': 1,
             'ltop': 1,
             'left': 3,
             'right': 4,
             'rbottom': 6,
             'lbottom': 5,
             'rtop': 2,
             'parity': 255
         }
     }])
     # Trans
     mols = list(
         pybel.readfile("pcjson", os.path.join(filedir,
                                               'CID_638186_2D.json')))
     output = json.loads(mols[0].write('pcjson'))
     self.assertEqual(output['PC_Compounds'][0]['stereo'], [{
         'planar': {
             'type': 1,
             'ltop': 2,
             'left': 3,
             'right': 4,
             'rbottom': 1,
             'lbottom': 5,
             'rtop': 6,
             'parity': 255
         }
     }])
     # Any
     mols = list(
         pybel.readfile("pcjson", os.path.join(filedir,
                                               'CID_10900_2D.json')))
     output = json.loads(mols[0].write('pcjson'))
     self.assertEqual(
         output['PC_Compounds'][0]['stereo'][0]['planar']['left'], 3)
     self.assertEqual(
         output['PC_Compounds'][0]['stereo'][0]['planar']['right'], 4)
     self.assertEqual(
         output['PC_Compounds'][0]['stereo'][0]['planar']['left'], 3)
コード例 #2
0
 def test_write_cid(self):
     """Test writing a PubChem compound CID."""
     mols = list(pybel.readfile("pcjson", os.path.join(filedir, 'CID_2244_2D.json')))
     output = json.loads(mols[0].write('pcjson'))
     self.assertEqual(len(output['PC_Compounds']), 1)
     self.assertTrue('id' in output['PC_Compounds'][0])
     self.assertEqual(output['PC_Compounds'][0]['id']['id']['cid'], '2244')
コード例 #3
0
 def test_read_atoms(self):
     """Test reading atoms for a PubChem compound."""
     mols = list(pybel.readfile("pcjson", os.path.join(filedir, 'CID_6857552_2D.json')))
     self.assertEqual(len(mols), 1)
     self.assertEqual(len(mols[0].atoms), 14)
     self.assertEqual([a.atomicnum for a in mols[0].atoms], [8, 8, 8, 7, 6, 6, 6, 1, 1, 1, 1, 1, 1, 1])
     self.assertEqual([a.formalcharge for a in mols[0].atoms], [0, -1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
コード例 #4
0
 def test_write_stereo_tetrahedral(self):
     """Test writing tetrahedral stereochemistry."""
     mols = list(pybel.readfile("pcjson", os.path.join(filedir, 'CID_6137_2D.json')))
     output = json.loads(mols[0].write('pcjson'))
     self.assertEqual(output['PC_Compounds'][0]['stereo'], [
         {'tetrahedral': {'above': 12, 'below': 5, 'bottom': 8, 'center': 6, 'parity': 1, 'top': 4, 'type': 1}}
     ])
コード例 #5
0
 def test_write_minified(self):
     """Test writing minified output."""
     mols = list(pybel.readfile("cdjson", os.path.join(filedir, 'butane.json')))
     output = mols[0].write('cdjson', opt={'m': None})
     self.assertTrue('\n' not in output)
     output = mols[0].write('cdjson')
     self.assertTrue('\n' in output)
コード例 #6
0
 def test_read_atoms(self):
     """Test reading atoms for a PubChem compound."""
     mols = list(pybel.readfile("pcjson", os.path.join(filedir, 'CID_6857552_2D.json')))
     self.assertEqual(len(mols), 1)
     self.assertEqual(len(mols[0].atoms), 14)
     self.assertEqual([a.atomicnum for a in mols[0].atoms], [8, 8, 8, 7, 6, 6, 6, 1, 1, 1, 1, 1, 1, 1])
     self.assertEqual([a.formalcharge for a in mols[0].atoms], [0, -1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
コード例 #7
0
 def test_read_proton(self):
     """Test reading a file with a single hydrogen atom (and no bonds)."""
     mols = list(pybel.readfile("cdjson", os.path.join(filedir, 'proton.json')))
     self.assertEqual(len(mols), 1)
     self.assertEqual(mols[0].OBMol.NumAtoms(), 1)
     self.assertEqual(mols[0].OBMol.GetAtom(1).GetFormalCharge(), 1)
     self.assertEqual(mols[0].OBMol.NumBonds(), 0)
コード例 #8
0
 def test_write_stereo_tetrahedral(self):
     """Test writing tetrahedral stereochemistry."""
     mols = list(pybel.readfile("pcjson", os.path.join(filedir, 'CID_6137_2D.json')))
     output = json.loads(mols[0].write('pcjson'))
     self.assertEqual(output['PC_Compounds'][0]['stereo'], [
         {'tetrahedral': {'above': 12, 'below': 5, 'bottom': 8, 'center': 6, 'parity': 1, 'top': 4, 'type': 1}}
     ])
コード例 #9
0
ファイル: testpcjsonformat.py プロジェクト: yueli9/openbabel
 def test_write_charge(self):
     """Test writing molecule charge."""
     mols = list(
         pybel.readfile("pcjson", os.path.join(filedir,
                                               'CID_1038_2D.json')))
     output = json.loads(mols[0].write('pcjson'))
     self.assertEqual(output['PC_Compounds'][0]['charge'], 1)
コード例 #10
0
 def test_read_multiple(self):
     """Test reading a file with multiple molecules."""
     mols = list(
         pybel.readfile("cdjson", os.path.join(filedir, 'butane.json')))
     self.assertEqual(len(mols), 2)
     self.assertEqual(mols[0].OBMol.NumAtoms(), 4)
     self.assertEqual(mols[1].OBMol.NumAtoms(), 4)
コード例 #11
0
 def test_write_cid(self):
     """Test writing a PubChem compound CID."""
     mols = list(pybel.readfile("pcjson", os.path.join(filedir, 'CID_2244_2D.json')))
     output = json.loads(mols[0].write('pcjson'))
     self.assertEqual(len(output['PC_Compounds']), 1)
     self.assertTrue('id' in output['PC_Compounds'][0])
     self.assertEqual(output['PC_Compounds'][0]['id']['id']['cid'], '2244')
コード例 #12
0
 def test_write_atoms(self):
     """Test writing atoms for a PubChem compound."""
     mols = list(pybel.readfile("pcjson", os.path.join(filedir, 'CID_6857552_2D.json')))
     output = json.loads(mols[0].write('pcjson'))
     self.assertEqual(output['PC_Compounds'][0]['atoms']['aids'], list(range(1, 15)))
     self.assertEqual(output['PC_Compounds'][0]['atoms']['element'], [8, 8, 8, 7, 6, 6, 6, 1, 1, 1, 1, 1, 1, 1])
     self.assertEqual(output['PC_Compounds'][0]['atoms']['charge'][0], {'aid': 2, 'value': -1})
     self.assertEqual(output['PC_Compounds'][0]['atoms']['charge'][1], {'aid': 4, 'value': 1})
コード例 #13
0
 def test_write_atoms(self):
     """Test writing atoms."""
     mols = list(pybel.readfile("cdjson", os.path.join(filedir, 'butane.json')))
     output = json.loads(mols[0].write('cdjson'))
     self.assertEqual(len(output['m'][0]['a']), 4)
     for a in output['m'][0]['a']:
         self.assertTrue('x' in a)
         self.assertTrue('y' in a)
コード例 #14
0
 def test_read_bonds(self):
     """Test reading bonds."""
     mols = list(
         pybel.readfile("cdjson", os.path.join(filedir, 'butane.json')))
     self.assertEqual(mols[0].OBMol.NumBonds(), 3)
     self.assertEqual(
         [mols[0].OBMol.GetBond(i).GetBondOrder() for i in range(0, 3)],
         [1, 1, 1])
コード例 #15
0
ファイル: testpcjsonformat.py プロジェクト: yueli9/openbabel
 def test_read_cid(self):
     """Test reading a PubChem compound CID."""
     mols = list(
         pybel.readfile("pcjson", os.path.join(filedir,
                                               'CID_2244_2D.json')))
     self.assertEqual(len(mols), 1)
     self.assertEqual(mols[0].data['cid'], '2244')
     self.assertEqual(mols[0].title, '2244')
コード例 #16
0
ファイル: testpcjsonformat.py プロジェクト: yueli9/openbabel
 def test_read_sid(self):
     """Test reading a PubChem substance SID."""
     mols = list(
         pybel.readfile("pcjson",
                        os.path.join(filedir, 'SID_348356775_2D.json')))
     self.assertEqual(len(mols), 1)
     self.assertEqual(mols[0].data['sid'], '348356775')
     self.assertEqual(mols[0].title, '348356775')
コード例 #17
0
 def test_write_atoms(self):
     """Test writing atoms for a PubChem compound."""
     mols = list(pybel.readfile("pcjson", os.path.join(filedir, 'CID_6857552_2D.json')))
     output = json.loads(mols[0].write('pcjson'))
     self.assertEqual(output['PC_Compounds'][0]['atoms']['aids'], list(range(1, 15)))
     self.assertEqual(output['PC_Compounds'][0]['atoms']['element'], [8, 8, 8, 7, 6, 6, 6, 1, 1, 1, 1, 1, 1, 1])
     self.assertEqual(output['PC_Compounds'][0]['atoms']['charge'][0], {'aid': 2, 'value': -1})
     self.assertEqual(output['PC_Compounds'][0]['atoms']['charge'][1], {'aid': 4, 'value': 1})
コード例 #18
0
ファイル: testpcjsonformat.py プロジェクト: yueli9/openbabel
 def test_write_complex_bonds(self):
     """Test writing complex bonds."""
     mols = list(
         pybel.readfile("pcjson",
                        os.path.join(filedir, 'CID_368849_2D.json'),
                        opt={'s': None}))
     output = json.loads(mols[0].write('pcjson', opt={'w': None}))
     self.assertEqual(output['PC_Compounds'][0]['bonds']['order'][:4],
                      [6, 6, 6, 6])
コード例 #19
0
ファイル: testpcjsonformat.py プロジェクト: yueli9/openbabel
 def test_read_bonds(self):
     """Test reading bonds for a PubChem compound."""
     mols = list(
         pybel.readfile("pcjson",
                        os.path.join(filedir, 'CID_6857552_2D.json')))
     self.assertEqual(len(mols), 1)
     self.assertEqual(mols[0].OBMol.NumBonds(), 13)
     self.assertEqual(
         [mols[0].OBMol.GetBond(i).GetBO() for i in range(0, 13)],
         [1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1])
コード例 #20
0
 def test_write_stereo_cistrans(self):
     """Test writing cis-trans stereochemistry."""
     # (Superfluous?) parity value is not set to same/opposite (1/2). unknown (255) is valid though.
     # Cis
     mols = list(pybel.readfile("pcjson", os.path.join(filedir, 'CID_643833_2D.json')))
     output = json.loads(mols[0].write('pcjson'))
     self.assertEqual(output['PC_Compounds'][0]['stereo'], [
         {'planar': {'type': 1, 'ltop': 1, 'left': 3, 'right': 4, 'rbottom': 6, 'lbottom': 5, 'rtop': 2, 'parity': 255}}
     ])
     # Trans
     mols = list(pybel.readfile("pcjson", os.path.join(filedir, 'CID_638186_2D.json')))
     output = json.loads(mols[0].write('pcjson'))
     self.assertEqual(output['PC_Compounds'][0]['stereo'], [
         {'planar': {'type': 1, 'ltop': 2, 'left': 3, 'right': 4, 'rbottom': 1, 'lbottom': 5, 'rtop': 6, 'parity': 255}}
     ])
     # Any
     mols = list(pybel.readfile("pcjson", os.path.join(filedir, 'CID_10900_2D.json')))
     output = json.loads(mols[0].write('pcjson'))
     self.assertEqual(output['PC_Compounds'][0]['stereo'][0]['planar']['left'], 3)
     self.assertEqual(output['PC_Compounds'][0]['stereo'][0]['planar']['right'], 4)
     self.assertEqual(output['PC_Compounds'][0]['stereo'][0]['planar']['left'], 3)
コード例 #21
0
 def test_write_bonds(self):
     """Test writing bonds."""
     mols = list(
         pybel.readfile("cdjson", os.path.join(filedir, 'butane.json')))
     output = json.loads(mols[0].write('cdjson'))
     self.assertEqual(output['m'][0]['b'], [{
         'b': 0,
         'e': 1
     }, {
         'b': 0,
         'e': 2
     }, {
         'b': 0,
         'e': 3
     }])
コード例 #22
0
 def test_read_atoms(self):
     """Test reading atoms."""
     mols = list(
         pybel.readfile("cdjson", os.path.join(filedir, 'butane.json')))
     self.assertEqual([a.atomicnum for a in mols[0].atoms], [6, 6, 6, 6])
     self.assertEqual([a.formalcharge for a in mols[0].atoms], [0, 0, 0, 0])
コード例 #23
0
 def test_write_complex_bonds(self):
     """Test writing complex bonds."""
     mols = list(pybel.readfile("pcjson", os.path.join(filedir, 'CID_368849_2D.json'), opt={'s': None}))
     output = json.loads(mols[0].write('pcjson', opt={'w': None}))
     self.assertEqual(output['PC_Compounds'][0]['bonds']['order'][:4], [6, 6, 6, 6])
コード例 #24
0
 def test_read_empty(self):
     """Test reading a file with an empty molecules array."""
     mols = list(
         pybel.readfile("cdjson", os.path.join(filedir, 'empty.json')))
     self.assertEqual(mols, [])
コード例 #25
0
 def test_write_charge(self):
     """Test writing molecule charge."""
     mols = list(pybel.readfile("pcjson", os.path.join(filedir, 'CID_1038_2D.json')))
     output = json.loads(mols[0].write('pcjson'))
     self.assertEqual(output['PC_Compounds'][0]['charge'], 1)
コード例 #26
0
 def test_write_bonds(self):
     """Test writing bonds."""
     mols = list(pybel.readfile("cdjson", os.path.join(filedir, 'butane.json')))
     output = json.loads(mols[0].write('cdjson'))
     self.assertEqual(output['m'][0]['b'], [{'b': 0, 'e': 1}, {'b': 0, 'e': 2}, {'b': 0, 'e': 3}])
コード例 #27
0
 def test_read_atoms(self):
     """Test reading atoms."""
     mols = list(pybel.readfile("cdjson", os.path.join(filedir, 'butane.json')))
     self.assertEqual([a.atomicnum for a in mols[0].atoms], [6, 6, 6, 6])
     self.assertEqual([a.formalcharge for a in mols[0].atoms], [0, 0, 0, 0])
コード例 #28
0
 def test_read_bonds(self):
     """Test reading bonds."""
     mols = list(pybel.readfile("cdjson", os.path.join(filedir, 'butane.json')))
     self.assertEqual(mols[0].OBMol.NumBonds(), 3)
     self.assertEqual([mols[0].OBMol.GetBond(i).GetBO() for i in range(0, 3)], [1, 1, 1])
コード例 #29
0
 def test_read_multiple(self):
     """Test reading a file with multiple molecules."""
     mols = list(pybel.readfile("cdjson", os.path.join(filedir, 'butane.json')))
     self.assertEqual(len(mols), 2)
     self.assertEqual(mols[0].OBMol.NumAtoms(), 4)
     self.assertEqual(mols[1].OBMol.NumAtoms(), 4)
コード例 #30
0
 def test_read_sid(self):
     """Test reading a PubChem substance SID."""
     mols = list(pybel.readfile("pcjson", os.path.join(filedir, 'SID_348356775_2D.json')))
     self.assertEqual(len(mols), 1)
     self.assertEqual(mols[0].data['sid'], '348356775')
     self.assertEqual(mols[0].title, '348356775')
コード例 #31
0
 def test_read_empty(self):
     """Test reading a file with an empty molecules array."""
     mols = list(pybel.readfile("cdjson", os.path.join(filedir, 'empty.json')))
     self.assertEqual(mols, [])
コード例 #32
0
 def test_read_cid(self):
     """Test reading a PubChem compound CID."""
     mols = list(pybel.readfile("pcjson", os.path.join(filedir, 'CID_2244_2D.json')))
     self.assertEqual(len(mols), 1)
     self.assertEqual(mols[0].data['cid'], '2244')
     self.assertEqual(mols[0].title, '2244')
コード例 #33
0
 def test_read_bonds(self):
     """Test reading bonds for a PubChem compound."""
     mols = list(pybel.readfile("pcjson", os.path.join(filedir, 'CID_6857552_2D.json')))
     self.assertEqual(len(mols), 1)
     self.assertEqual(mols[0].OBMol.NumBonds(), 13)
     self.assertEqual([mols[0].OBMol.GetBond(i).GetBO() for i in range(0, 13)], [1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1])