def test_atom(self): """Test the lib.structure.pdb_read.atom() function.""" # Parse a PDB record. record = pdb_read.atom('ATOM 158 CG GLU 11 9.590 -1.041 -11.596 1.00 0.00 C ') # Test the elements. self.assertEqual(record[0], 'ATOM') self.assertEqual(record[1], 158) self.assertEqual(record[2], 'CG') self.assertEqual(record[3], None) self.assertEqual(record[4], 'GLU') self.assertEqual(record[5], None) self.assertEqual(record[6], 11) self.assertEqual(record[7], None) self.assertEqual(record[8], 9.59) self.assertEqual(record[9], -1.041) self.assertEqual(record[10], -11.596) self.assertEqual(record[11], 1.0) self.assertEqual(record[12], 0.0) self.assertEqual(record[13], 'C') self.assertEqual(record[14], None)
def fill_object_from_pdb(self, records, alt_loc_select=None): """Method for generating a complete Structure_container object from the given PDB records. @param records: A list of structural PDB records. @type records: list of str @keyword alt_loc_select: The PDB ATOM record 'Alternate location indicator' field value to select which coordinates to use. @type alt_loc_select: str or None """ # Loop over the records. for record in records: # Nothing to do. if not record or record == '\n': continue # Add the atom. if record[:4] == 'ATOM' or record[:6] == 'HETATM': # Parse the record. if record[:4] == 'ATOM': record_type, serial, name, alt_loc, res_name, chain_id, res_seq, icode, x, y, z, occupancy, temp_factor, element, charge = pdb_read.atom(record) if record[:6] == 'HETATM': record_type, serial, name, alt_loc, res_name, chain_id, res_seq, icode, x, y, z, occupancy, temp_factor, element, charge = pdb_read.hetatm(record) # Handle the alternate locations. if alt_loc != None: # Don't know what to do. if alt_loc_select == None: raise RelaxError("Multiple alternate location indicators are present in the PDB file, but the desired coordinate set has not been specified.") # Skip non-matching locations. if alt_loc != alt_loc_select: continue # Attempt at determining the element, if missing. if not element: element = self._det_pdb_element(name) # Add. self.atom_add(pdb_record=record_type, atom_num=serial, atom_name=name, res_name=res_name, chain_id=chain_id, res_num=res_seq, pos=[x, y, z], element=element) # Connect atoms. if record[:6] == 'CONECT': # Parse the record. record_type, serial, bonded1, bonded2, bonded3, bonded4 = pdb_read.conect(record) # Loop over the atoms of the record. for bonded in [bonded1, bonded2, bonded3, bonded4]: # Skip if there is no record. if not bonded: continue # Skip broken CONECT records (for when the record points to a non-existent atom). if self._atom_index(serial) == None or self._atom_index(bonded) == None: continue # Make the connection. self.atom_connect(index1=self._atom_index(serial), index2=self._atom_index(bonded))
def fill_object_from_pdb(self, records, alt_loc_select=None): """Method for generating a complete Structure_container object from the given PDB records. @param records: A list of structural PDB records. @type records: list of str @keyword alt_loc_select: The PDB ATOM record 'Alternate location indicator' field value to select which coordinates to use. @type alt_loc_select: str or None """ # Loop over the records. water = [] missing_connect = [] for record in records: # Nothing to do. if not record or record == '\n': continue # Add the atom. if record[:4] == 'ATOM' or record[:6] == 'HETATM': # Parse the record. if record[:4] == 'ATOM': record_type, serial, name, alt_loc, res_name, chain_id, res_seq, icode, x, y, z, occupancy, temp_factor, element, charge = pdb_read.atom(record) if record[:6] == 'HETATM': record_type, serial, name, alt_loc, res_name, chain_id, res_seq, icode, x, y, z, occupancy, temp_factor, element, charge = pdb_read.hetatm(record) # Skip waters. if res_name == 'HOH': water.append(res_seq) continue # Handle the alternate locations. if alt_loc != None: # Don't know what to do. if alt_loc_select == None: raise RelaxError("Multiple alternate location indicators are present in the PDB file, but the desired coordinate set has not been specified.") # Skip non-matching locations. if alt_loc != alt_loc_select: continue # Attempt at determining the element, if missing. if not element: element = self._det_pdb_element(name) # Add. self.atom_add(pdb_record=record_type, atom_num=serial, atom_name=name, res_name=res_name, chain_id=chain_id, res_num=res_seq, pos=[x, y, z], element=element) # Connect atoms. if record[:6] == 'CONECT': # Parse the record. record_type, serial, bonded1, bonded2, bonded3, bonded4 = pdb_read.conect(record) # Loop over the atoms of the record. for bonded in [bonded1, bonded2, bonded3, bonded4]: # Skip if there is no record. if not bonded: continue # The atom indices. serial_index = self._atom_index(serial) bonded_index = self._atom_index(bonded) # Skip broken CONECT records (for when the record points to a non-existent atom). if serial_index == None: if serial not in missing_connect: missing_connect.append(serial) continue if bonded_index == None: if bonded not in missing_connect: missing_connect.append(bonded) continue # Make the connection. self.atom_connect(index1=serial_index, index2=bonded_index) # Warnings. if len(missing_connect): missing_connect.sort() warn(RelaxWarning("The following atom numbers from the CONECT records cannot be found within the ATOM and HETATM records: %s." % missing_connect)) if len(water): warn(RelaxWarning("Skipping the water molecules HOH %s." % water))
def fill_object_from_pdb(self, records, alt_loc_select=None, reset_serial=True): """Method for generating a complete Structure_container object from the given PDB records. @param records: A list of structural PDB records. @type records: list of str @keyword alt_loc_select: The PDB ATOM record 'Alternate location indicator' field value to select which coordinates to use. @type alt_loc_select: str or None @keyword reset_serial: A flag which if True will cause the first serial number (or atom number) to be reset to 1, and all other numbers shifted. @type reset_serial: bool """ # Loop over the records. water = [] missing_connect = [] number_offset = None for record in records: # Nothing to do. if not record or record == '\n': continue # Add the atom. if record[:4] == 'ATOM' or record[:6] == 'HETATM': # Parse the record. if record[:4] == 'ATOM': record_type, serial, name, alt_loc, res_name, chain_id, res_seq, icode, x, y, z, occupancy, temp_factor, element, charge = pdb_read.atom( record) if record[:6] == 'HETATM': record_type, serial, name, alt_loc, res_name, chain_id, res_seq, icode, x, y, z, occupancy, temp_factor, element, charge = pdb_read.hetatm( record) # The serial number. if reset_serial: # The first number. if number_offset == None: number_offset = serial - 1 # Reset. serial -= number_offset # Skip waters. if res_name == 'HOH': water.append(res_seq) continue # Handle the alternate locations. if alt_loc != None: # Don't know what to do. if alt_loc_select == None: raise RelaxError( "Multiple alternate location indicators are present in the PDB file, but the desired coordinate set has not been specified." ) # Skip non-matching locations. if alt_loc != alt_loc_select: continue # Attempt at determining the element, if missing. if not element: element = self._det_pdb_element(name) # Add. self.atom_add(pdb_record=record_type, atom_num=serial, atom_name=name, res_name=res_name, res_num=res_seq, pos=[x, y, z], element=element) # Connect atoms. if record[:6] == 'CONECT': # Parse the record. record_type, serial, bonded1, bonded2, bonded3, bonded4 = pdb_read.conect( record) # Reset the serial numbers. if reset_serial: serial -= number_offset bonded1 -= number_offset if bonded2 != None: bonded2 -= number_offset if bonded3 != None: bonded3 -= number_offset if bonded4 != None: bonded4 -= number_offset # Loop over the atoms of the record. for bonded in [bonded1, bonded2, bonded3, bonded4]: # Skip if there is no record. if not bonded: continue # The atom indices. serial_index = self._atom_index(serial) bonded_index = self._atom_index(bonded) # Skip broken CONECT records (for when the record points to a non-existent atom). if serial_index == None: if serial not in missing_connect: missing_connect.append(serial) continue if bonded_index == None: if bonded not in missing_connect: missing_connect.append(bonded) continue # Make the connection. self.atom_connect(index1=serial_index, index2=bonded_index) # Warnings. if len(missing_connect): missing_connect.sort() warn( RelaxWarning( "The following atom numbers from the CONECT records cannot be found within the ATOM and HETATM records: %s." % missing_connect)) if len(water): warn(RelaxWarning("Skipping the water molecules HOH %s." % water))