def testWriteDataFile(self): """Test case - write data file """ try: # myDataList = [] curContainer = DataContainer("myblock") aCat = DataCategory("pdbx_seqtool_mapping_ref") aCat.appendAttribute("ordinal") aCat.appendAttribute("entity_id") aCat.appendAttribute("auth_mon_id") aCat.appendAttribute("auth_mon_num") aCat.appendAttribute("pdb_chain_id") aCat.appendAttribute("ref_mon_id") aCat.appendAttribute("ref_mon_num") aCat.append((1, 2, 3, 4, "55555555555555555555555555555555555555555555", 6, 7)) aCat.append((1, 2, 3, 4, "5555", 6, 7)) aCat.append((1, 2, 3, 4, "5555555555", 6, 7)) aCat.append((1, 2, 3, 4, "5", 6, 7)) curContainer.append(aCat) myDataList.append(curContainer) with open(self.__pathOutputFile1, "w") as ofh: pdbxW = PdbxWriter(ofh) pdbxW.setAlignmentFlag(flag=True) pdbxW.write(myDataList) self.assertEqual(len(myDataList), 1) except Exception as e: logger.exception("Failing with %s", str(e)) self.fail()
def __writeFile( self, ofh, containerList, maxLineLength=900, columnAlignFlag=True, lastInOrder=None, selectOrder=None, useStopTokens=False, formattingStep=None, enforceAscii=False, cnvCharRefs=False, ): """Internal method mapping arguments to PDBxWriter API.""" # pdbxW = PdbxWriter(ofh) pdbxW.setUseStopTokens(flag=useStopTokens) pdbxW.setMaxLineLength(numChars=maxLineLength) pdbxW.setAlignmentFlag(flag=columnAlignFlag) pdbxW.setRowPartition(numParts=formattingStep) pdbxW.setConvertCharRefs(flag=cnvCharRefs) pdbxW.setSetEnforceAscii(enforceAscii) pdbxW.write(containerList, lastInOrder=lastInOrder, selectOrder=selectOrder)
def _createfile1(pathout): my_data_list = [] cur_container = DataContainer("myblock") acat = DataCategory("pdbx_item_enumeration") acat.appendAttribute("name") acat.appendAttribute("value") acat.appendAttribute("detail") acat.append(('1', '2', '3')) cur_container.append(acat) acat = DataCategory("exptl") acat.appendAttribute('absorpt_coefficient_mu') acat.appendAttribute('entry_id') acat.appendAttribute('method') acat.appendAttribute('details') acat.append(('?', 'D_12345', 'X-RAY DIFFRACTION', 'some details')) cur_container.append(acat) acat = DataCategory("struct") acat.appendAttribute('title') acat.appendAttribute('pdbx_descriptor') acat.append(('Start title', 'Start Descriptor')) cur_container.append(acat) my_data_list.append(cur_container) # Second block cur_container = DataContainer("secondblock") acat = DataCategory("pdbx_item_enumeration") acat.appendAttribute("name") acat.appendAttribute("value") acat.appendAttribute("detail") acat.append(('3', '2', '1')) cur_container.append(acat) my_data_list.append(cur_container) with open(pathout, "w") as ofh: pdbxw = PdbxWriter(ofh) pdbxw.setAlignmentFlag(flag=True) pdbxw.write(my_data_list)
def _createfile1(pathout): my_data_list = [] cur_container = DataContainer("myblock") acat = DataCategory("pdbx_item_enumeration") acat.appendAttribute("name") acat.appendAttribute("value") acat.appendAttribute("detail") acat.append(("1", "2", "3")) cur_container.append(acat) acat = DataCategory("exptl") acat.appendAttribute("absorpt_coefficient_mu") acat.appendAttribute("entry_id") acat.appendAttribute("method") acat.appendAttribute("details") acat.append(("?", "D_12345", "X-RAY DIFFRACTION", "some details")) cur_container.append(acat) acat = DataCategory("struct") acat.appendAttribute("title") acat.appendAttribute("pdbx_descriptor") acat.append(("Start title", "Start Descriptor")) cur_container.append(acat) my_data_list.append(cur_container) # Second block cur_container = DataContainer("secondblock") acat = DataCategory("pdbx_item_enumeration") acat.appendAttribute("name") acat.appendAttribute("value") acat.appendAttribute("detail") acat.append(("3", "2", "1")) cur_container.append(acat) my_data_list.append(cur_container) with open(pathout, "w") as ofh: pdbxw = PdbxWriter(ofh) pdbxw.setAlignmentFlag(flag=True) pdbxw.write(my_data_list)
def _createfile2(pathout): my_data_list = [] cur_container = DataContainer("test") acat = DataCategory("new") acat.appendAttribute("item") acat.append(('1',)) cur_container.append(acat) acat = DataCategory("second_category") acat.appendAttribute('row') acat.appendAttribute('rowb') acat.append(('1', '2')) cur_container.append(acat) acat = DataCategory("third") acat.appendAttribute('id') acat.appendAttribute('val') acat.append(('1', 'a')) acat.append(('2', 'b')) acat.append(('3', 'c')) cur_container.append(acat) acat = DataCategory("exptl") acat.appendAttribute('method') acat.appendAttribute('entry_id') acat.append(('NEW', 'something')) cur_container.append(acat) acat = DataCategory("struct") acat.appendAttribute('new') acat.appendAttribute('pdbx_descriptor') acat.append(('Something to add', 'Override descriptor')) cur_container.append(acat) my_data_list.append(cur_container) with open(pathout, "w") as ofh: pdbxw = PdbxWriter(ofh) pdbxw.setAlignmentFlag(flag=True) pdbxw.write(my_data_list)
def _createfile2(pathout): my_data_list = [] cur_container = DataContainer("test") acat = DataCategory("new") acat.appendAttribute("item") acat.append(("1",)) cur_container.append(acat) acat = DataCategory("second_category") acat.appendAttribute("row") acat.appendAttribute("rowb") acat.append(("1", "2")) cur_container.append(acat) acat = DataCategory("third") acat.appendAttribute("id") acat.appendAttribute("val") acat.append(("1", "a")) acat.append(("2", "b")) acat.append(("3", "c")) cur_container.append(acat) acat = DataCategory("exptl") acat.appendAttribute("method") acat.appendAttribute("entry_id") acat.append(("NEW", "something")) cur_container.append(acat) acat = DataCategory("struct") acat.appendAttribute("new") acat.appendAttribute("pdbx_descriptor") acat.append(("Something to add", "Override descriptor")) cur_container.append(acat) my_data_list.append(cur_container) with open(pathout, "w") as ofh: pdbxw = PdbxWriter(ofh) pdbxw.setAlignmentFlag(flag=True) pdbxw.write(my_data_list)
def test_write_data_file(self, writer_paths): myDataList = [] curContainer = DataContainer("myblock") aCat = DataCategory("pdbx_seqtool_mapping_ref") aCat.appendAttribute("ordinal") aCat.appendAttribute("entity_id") aCat.appendAttribute("auth_mon_id") aCat.appendAttribute("auth_mon_num") aCat.appendAttribute("pdb_chain_id") aCat.appendAttribute("ref_mon_id") aCat.appendAttribute("ref_mon_num") aCat.append( (1, 2, 3, 4, '55555555555555555555555555555555555555555555', 6, 7)) aCat.append((1, 2, 3, 4, '5555', 6, 7)) aCat.append((1, 2, 3, 4, '5555555555', 6, 7)) aCat.append((1, 2, 3, 4, '5', 6, 7)) curContainer.append(aCat) myDataList.append(curContainer) with open(str(writer_paths['pathOutputFile1']), "w") as ofh: pdbxW = PdbxWriter(ofh) pdbxW.setAlignmentFlag(flag=True) pdbxW.write(myDataList) assert len(myDataList) == 1