Author: bugman Date: Fri Feb 20 10:07:31 2015 New Revision: 27690 URL: http://svn.gna.org/viewcvs/relax?rev=27690&view=rev Log: Improved the RelaxWarning for missing atom numbers in the PDB CONECT records. This is for the structure.read_pdb user function. Now only one warning is given for the entire PDB file listing all of the missing atom numbers rather than one warning per missing atom. This can significantly compact the warnings, removing a lot of repetition. Modified: trunk/lib/structure/internal/molecules.py Modified: trunk/lib/structure/internal/molecules.py URL: http://svn.gna.org/viewcvs/relax/trunk/lib/structure/internal/molecules.py?rev=27690&r1=27689&r2=27690&view=diff ============================================================================== --- trunk/lib/structure/internal/molecules.py (original) +++ trunk/lib/structure/internal/molecules.py Fri Feb 20 10:07:31 2015 @@ -114,9 +114,6 @@ if self.atom_num[j] == atom_num: return j - # Should not be here, the PDB connect records are incorrect. - warn(RelaxWarning("The atom number " + repr(atom_num) + " from the CONECT record cannot be found within the ATOM and HETATM records.")) - def _det_pdb_element(self, atom_name): """Try to determine the element from the PDB atom name. @@ -394,6 +391,7 @@ # Loop over the records. water = [] + missing_connect = [] for record in records: # Nothing to do. if not record or record == '\n': @@ -440,13 +438,27 @@ 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 self._atom_index(serial) == None or self._atom_index(bonded) == None: + 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=self._atom_index(serial), index2=self._atom_index(bonded)) - + 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))