Esempio n. 1
0
 def test_inData_outWrap(self):
     cfr = CifFileReader(input='data')
     cif_wrapper = cfr.read(self.TEST_CIF_FILE, output='cif_wrapper')
     self.assertIsInstance(cif_wrapper["TEST_CIF"], CIFWrapper, "Failed to create CIFWrapper using lexical parser")
     self.assertListEqual(list(cif_wrapper.keys()), ["TEST_CIF", "BLOCK_2"], "DataBlocks not read correctly")
     self.assertEqual(cif_wrapper["BLOCK_2"]._extra.strange_value[0], "Three#Blind#Mice",
         "All levels of CIF file not translated to dictionary correctly")
Esempio n. 2
0
 def test_inData_outDict(self):
     cfr = CifFileReader(input='data')
     cif_dictionary = cfr.read(self.TEST_CIF_FILE, output='cif_dictionary')
     self.assertIsInstance(cif_dictionary, dict, "Failed to create python dictionary from cif file")
     self.assertListEqual(list(cif_dictionary.keys()), ["TEST_CIF", "BLOCK_2"], "DataBlocks not read correctly")
     self.assertEqual(cif_dictionary["BLOCK_2"]["_extra"]["strange_value"], "Three#Blind#Mice",
         "All levels of CIF file not translated to dictionary correctly")
Esempio n. 3
0
 def test_inDict_outFile(self):
     cfr = CifFileReader(input='dictionary')
     cif_file = cfr.read(self.TEST_CIF_FILE, output='cif_file')
     self.assertIsInstance(cif_file, CifFile, "Failed to create CifFile using lexical parser")
     self.assertListEqual(cif_file.getDataBlockIds(), ["TEST_CIF", "BLOCK_2"], "DataBlocks not read correctly")
     self.assertEqual(cif_file.getDataBlock("BLOCK_2").getCategory("_extra").getItem("strange_value").value,
         "Three#Blind#Mice",
         "All levels of CIF file not translated to dictionary correctly")
def read_ccd():
    print('Reading components.cif ...')
    sys.stdout.flush()
    components = CifFileReader()
    all_residues = components.read('components.cif')
    print('Reading aa-variants-v1.cif ...')
    amino_variants = components.read('aa-variants-v1.cif')
    return itertools.chain(iter(all_residues.items()), iter(amino_variants.items()))
def read_ccd():
    print 'Reading components.cif ...'
    sys.stdout.flush()
    components = CifFileReader()
    all_residues = components.read('components.cif')
    print 'Reading aa-variants-v1.cif ...'
    amino_variants = components.read('aa-variants-v1.cif')
    return itertools.chain(all_residues.iteritems(), amino_variants.iteritems())
Esempio n. 6
0
 def test_write_mmCIF_dictionary(self):
     unit_test_file = "io_testcase_5.cif"
     cfr = CifFileReader(input='dictionary')
     cif_file = cfr.read(self.TEST_DIC_FILE, output='cif_file')
     cfw = CifFileWriter(file_path=os.path.join(self.FILE_ROOT, unit_test_file))
     cfw.write(cif_file)
     test_file = cfr.read(os.path.join(self.FILE_ROOT, unit_test_file), output='cif_file')
     test_value = test_file.getDataBlock('TEST')\
         .getSaveFrame('some_interesting_category')\
         .getCategory('category')\
         .getItem('mandatory_code')\
         .value
     self.assertEquals(test_value, 'no', 'mmCIF dictionary file was not written correctly')
Esempio n. 7
0
 def test_ignoreCategories(self):
     cfr = CifFileReader(input='data')
     cif_file = cfr.read(self.TEST_CIF_FILE, output='cif_file', ignore=['_test_loop_2', '_valid_CIF'])
     self.assertIsInstance(cif_file, CifFile, "Failed to create CifFile using algorithmic parser")
     self.assertListEqual(cif_file.getDataBlockIds(), ["TEST_CIF", "BLOCK_2"], "DataBlocks not read correctly")
     categories_A = cif_file.getDataBlock("TEST_CIF").getCategoryIds()
     categories_A.sort()
     self.assertEqual(categories_A,
         ['test_keyword', 'test_loop_1', 'valid_cif'],
         "Categories were not ignored correctly")
     categories_B = cif_file.getDataBlock("BLOCK_2").getCategoryIds()
     categories_B.sort()
     self.assertEqual(categories_B,
         ['equivalence_test', 'extra'],
         "Categories were not ignored correctly")
Esempio n. 8
0
 def test_write_raw_dictionary_without_block_id(self):
     unit_test_file = "io_testcase_4.cif"
     # Test raw dictionary (WITHOUT datablock id)
     cfw = CifFileWriter(file_path=os.path.join(self.FILE_ROOT, unit_test_file))
     cfw.write(self.raw_dictionary['TEST_BLOCK_1'])
     del cfw
     cfr = CifFileReader(input='data')
     test_file = cfr.read(os.path.join(self.FILE_ROOT, unit_test_file), output='cif_wrapper')
     data_block_ids = test_file.keys()
     data_block_ids.sort()
     self.assertEqual(data_block_ids,
         [unit_test_file,],
         "Datablock(s) were not written correctly")
     self.assertEqual(test_file[unit_test_file]._test_category_2.test_value_1,
         ['1', '2', '3', '4'],
         "mmCIF data  was not written correctly")
Esempio n. 9
0
 def test_write_ciffile_after_ciffile_dictionary_import(self):
     # Test write CifFile initialized by dictionary
     unit_test_file = "io_testcase_1.cif"
     cfw = CifFileWriter()
     cif_file = CifFile(os.path.join(self.FILE_ROOT, unit_test_file))
     cif_file.import_mmcif_data_map(self.raw_dictionary)
     cfw.write(cif_file)
     cfr = CifFileReader(input='data')
     test_file = cfr.read(os.path.join(self.FILE_ROOT, unit_test_file), output='cif_wrapper')
     data_block_ids = test_file.keys()
     data_block_ids.sort()
     self.assertEqual(data_block_ids,
         ['TEST_BLOCK_1', 'TEST_BLOCK_2'],
         "Datablock(s) were not written correctly")
     self.assertEqual(test_file['TEST_BLOCK_1']._test_category_2.test_value_1,
         ['1', '2', '3', '4'],
         "mmCIF data  was not written correctly")
Esempio n. 10
0
 def test_write_ciffile_after_cifwrapper_dictionary_import(self):
     # Test write CifFile initialized by CIFWrapper and dictionary import
     unit_test_file = "io_testcase_2.cif"
     cfw = CifFileWriter(file_path=os.path.join(self.FILE_ROOT, unit_test_file))
     cif_obj = dict((k, CIFWrapper(v)) for k, v in self.raw_dictionary.items())
     cif_wrapper = CIFWrapper({'TEST_BLOCK_1': self.raw_dictionary['TEST_BLOCK_1']})
     cfw.write(cif_wrapper)
     cif_wrapper = CIFWrapper({'TEST_BLOCK_2': self.raw_dictionary['TEST_BLOCK_2']})
     cfw.write(cif_wrapper)
     del cfw
     cfr = CifFileReader(input='data')
     test_file = cfr.read(os.path.join(self.FILE_ROOT, unit_test_file), output='cif_wrapper')
     data_block_ids = test_file.keys()
     data_block_ids.sort()
     self.assertEqual(data_block_ids,
         ['TEST_BLOCK_1', 'TEST_BLOCK_2'],
         "Datablock(s) were not written correctly")
     self.assertEqual(test_file['TEST_BLOCK_1']._test_category_2.test_value_1,
         ['1', '2', '3', '4'],
         "mmCIF data  was not written correctly")
sys.path.insert(0, '..')
import utils

# to install mmCif: pip install git+git://github.com/glenveegee/PDBeCIF
from mmCif.mmcifIO import CifFileReader

ORDERS = dict(SING=1, DOUB=2, TRIP=3)

if __name__ == '__main__':
    print 'This program regenerates the `residue_bonds` database using the "Chemical Component '
    print 'Dictionary" and "Protonation Variants Dictionary" from http://www.wwpdb.org/data/ccd'
    print 'These files are not included in the repository and must be downloaded manually.\n'
    print 'Reading components.cif ...'
    sys.stdout.flush()

    components = CifFileReader()
    all_residues = components.read('components.cif')

    print 'Reading aa-variants-v1.cif ...'
    amino_variants = components.read('aa-variants-v1.cif')

    residues = []

    db = utils.CompressedJsonDbm('residue_bonds', 'n')

    for resname, data in itertools.chain(all_residues.iteritems(),
                                         amino_variants.iteritems()):
        if '_chem_comp_bond' not in data:
            print '\nskipped %s (no bonds)' % resname
            continue