def __call__(self, t): structure = t[1] # Precalculate indices numChains = structure.chains_per_model[0] chainToEntityIndex = self._get_chain_to_entity_index(structure) atomsPerChain, bondsPerChain = self._get_num_atoms_and_bonds(structure) chainList = list() seqSet = set() groupCounter = 0 atomCounter = 0 for i in range(numChains): polymerChain = MMTFEncoder() entityToChainIndex = chainToEntityIndex[i] chain_type = structure.entity_list[entityToChainIndex]['type'] polymer = chain_type == "polymer" polymerAtomCount = 0 atomMap = {} structureId = '' if polymer: # To avoid of information loss, add chainName/IDs and entity id # This required by some queries structureId = structure.structure_id + '.' +\ structure.chain_name_list[i] + '.' +\ structure.chain_id_list[i] + '.' +\ str(entityToChainIndex + 1) # Set header polymerChain.init_structure(bondsPerChain[i], atomsPerChain[i], structure.groups_per_chain[i], 1, 1, structureId) decoder_utils.add_xtalographic_info(structure, polymerChain) decoder_utils.add_header_info(structure, polymerChain) # Set model info (only one model: 0) polymerChain.set_model_info(0, 1) # Set entity and chain info polymerChain.set_entity_info( [0], structure.entity_list[entityToChainIndex]['sequence'], structure.entity_list[entityToChainIndex]['description'], structure.entity_list[entityToChainIndex]['type']) polymerChain.set_chain_info(structure.chain_id_list[i], structure.chain_name_list[i], structure.groups_per_chain[i]) for j in range(structure.groups_per_chain[i]): groupIndex = structure.group_type_list[groupCounter] if polymer: # Set group info polymerChain.set_group_info( structure.group_list[groupIndex]['groupName'], structure.group_id_list[groupCounter], structure.ins_code_list[groupCounter], structure.group_list[groupIndex]['chemCompType'], len(structure.group_list[groupIndex]['atomNameList']), len(structure.group_list[groupIndex]['bondOrderList']), structure.group_list[groupIndex]['singleLetterCode'], structure.sequence_index_list[groupCounter], structure.sec_struct_list[groupCounter]) for k in range( len(structure.group_list[groupIndex]['atomNameList'])): if polymer: atomMap[atomCounter] = polymerAtomCount polymerAtomCount += 1 polymerChain.set_atom_info( structure.group_list[groupIndex]['atomNameList'] [k], structure.atom_id_list[atomCounter], structure.alt_loc_list[atomCounter], structure.x_coord_list[atomCounter], structure.y_coord_list[atomCounter], structure.z_coord_list[atomCounter], structure.occupancy_list[atomCounter], structure.b_factor_list[atomCounter], structure.group_list[groupIndex]['elementList'][k], structure.group_list[groupIndex] ['formalChargeList'][k], ) atomCounter += 1 if polymer: # Add intra-group bond info for l in range( len(structure.group_list[groupIndex] ['bondOrderList'])): bondIndOne = structure.group_list[groupIndex][ 'bondAtomList'][l * 2] bondIndTwo = structure.group_list[groupIndex][ 'bondAtomList'][l * 2 + 1] bondOrder = structure.group_list[groupIndex][ 'bondOrderList'][l] polymerChain.set_group_bond(bondIndOne, bondIndTwo, bondOrder) groupCounter += 1 if polymer: # TODO skipping adding inter group bond info for now polymerChain.finalize_structure() chId = structure.chain_name_list[i] if self.useChainIdInsteadOfChainName: chId = structure.chain_id_list[i] if self.excludeDuplicates: if chainToEntityIndex[i] in seqSet: continue seqSet.add(chainToEntityIndex[i]) chainList.append( (structure.structure_id + "." + chId, polymerChain)) return chainList
def _combine_chains(self, s1, s2): if not s1.alt_loc_set: s1 = s1.set_alt_loc_list() if not s2.alt_loc_set: s2 = s2.set_alt_loc_list() groupCounter = 0 atomCounter = 0 structureId = s1.structure_id + "_append_" + s2.structure_id combinedStructure = MMTFEncoder() # Set header combinedStructure.init_structure(s1.num_bonds + s2.num_bonds, s1.num_atoms + s2.num_atoms, s1.num_groups + s2.num_groups, 2, 1, structureId) decoder_utils.add_xtalographic_info(s1, combinedStructure) decoder_utils.add_header_info(s1, combinedStructure) # Set model info (only one model: 0) combinedStructure.set_model_info(0, 2) chainToEntityIndex = self._get_chain_to_entity_index(s1)[0] # Set entity and chain info combinedStructure.set_entity_info( [0], s1.entity_list[chainToEntityIndex]['sequence'], s1.entity_list[chainToEntityIndex]['description'], s1.entity_list[chainToEntityIndex]['type']) combinedStructure.set_chain_info(s1.chain_id_list[0], s1.chain_name_list[0], s1.groups_per_chain[0]) for i in range(s1.groups_per_chain[0]): groupIndex = s1.group_type_list[groupCounter] # Set group info combinedStructure.set_group_info( s1.group_list[groupIndex]['groupName'], s1.group_id_list[groupCounter], s1.ins_code_list[groupCounter], s1.group_list[groupIndex]['chemCompType'], len(s1.group_list[groupIndex]['atomNameList']), len(s1.group_list[groupIndex]['bondOrderList']), s1.group_list[groupIndex]['singleLetterCode'], s1.sequence_index_list[groupCounter], s1.sec_struct_list[groupCounter]) for j in range(len(s1.group_list[groupIndex]['atomNameList'])): combinedStructure.set_atom_info( s1.group_list[groupIndex]['atomNameList'][j], s1.atom_id_list[atomCounter], s1.alt_loc_list[atomCounter], s1.x_coord_list[atomCounter], s1.y_coord_list[atomCounter], s1.z_coord_list[atomCounter], s1.occupancy_list[atomCounter], s1.b_factor_list[atomCounter], s1.group_list[groupIndex]['elementList'][j], s1.group_list[groupIndex]['formalChargeList'][j]) atomCounter += 1 # TODO not sure if we should add bonds like this # TODO bondAtomList == getGroupBondIndices? for k in range(len(s1.group_list[groupIndex]["bondOrderList"])): bondIndOne = s1.group_list[groupIndex]["bondAtomList"][k * 2] bondIndTwo = s1.group_list[groupIndex]["bondAtomList"][k * 2 + 1] bondOrder = s1.group_list[groupIndex]["bondOrderList"][k] combinedStructure.set_group_bond(bondIndOne, bondIndTwo, bondOrder) groupCounter += 1 # Set entity and chain info for s2 chainToEntityIndex = self._get_chain_to_entity_index(s2)[0] combinedStructure.set_entity_info( [1], s2.entity_list[chainToEntityIndex]['sequence'], s2.entity_list[chainToEntityIndex]['description'], s2.entity_list[chainToEntityIndex]['type']) combinedStructure.set_chain_info(s2.chain_id_list[0], s2.chain_name_list[0], s2.groups_per_chain[0]) groupCounter = 0 atomCounter = 0 for i in range(s2.groups_per_chain[0]): groupIndex = s2.group_type_list[groupCounter] # Set group info combinedStructure.set_group_info( s2.group_list[groupIndex]['groupName'], s2.group_id_list[groupCounter], s2.ins_code_list[groupCounter], s2.group_list[groupIndex]['chemCompType'], len(s2.group_list[groupIndex]['atomNameList']), len(s2.group_list[groupIndex]['bondOrderList']), s2.group_list[groupIndex]['singleLetterCode'], s2.sequence_index_list[groupCounter], s2.sec_struct_list[groupCounter]) for j in range(len(s2.group_list[groupIndex]['atomNameList'])): combinedStructure.set_atom_info( s2.group_list[groupIndex]['atomNameList'][j], s2.atom_id_list[atomCounter], s2.alt_loc_list[atomCounter], s2.x_coord_list[atomCounter], s2.y_coord_list[atomCounter], s2.z_coord_list[atomCounter], s2.occupancy_list[atomCounter], s2.b_factor_list[atomCounter], s2.group_list[groupIndex]['elementList'][j], s2.group_list[groupIndex]['formalChargeList'][j]) atomCounter += 1 # TODO not sure if we should add bonds like this # TODO bondAtomList == getGroupBondIndices? for k in range(len(s2.group_list[groupIndex]["bondOrderList"])): bondIndOne = s2.group_list[groupIndex]["bondAtomList"][k * 2] bondIndTwo = s2.group_list[groupIndex]["bondAtomList"][k * 2 + 1] bondOrder = s2.group_list[groupIndex]["bondOrderList"][k] combinedStructure.set_group_bond(bondIndOne, bondIndTwo, bondOrder) groupCounter += 1 combinedStructure.finalize_structure() return (structureId, combinedStructure)