Author: bugman Date: Mon Jan 27 18:54:40 2014 New Revision: 22050 URL: http://svn.gna.org/viewcvs/relax?rev=22050&view=rev Log: Merged revisions 22049 via svnmerge from svn+ssh://bugman@xxxxxxxxxxx/svn/relax/trunk ........ r22049 | bugman | 2014-01-27 18:54:08 +0100 (Mon, 27 Jan 2014) | 8 lines Large speed up for the internal structural object for when many models are present. The new ModelList.current_models object keeps track of all the models already present in the structural object. This simplifies the checks of the pack_structs() internal structural object method by removing expensive looping. This allows the loading of PDB files to continue to be fast even with many tens or hundreds of thousands of models already loaded. ........ Modified: branches/double_rotor/ (props changed) branches/double_rotor/lib/structure/internal/models.py branches/double_rotor/lib/structure/internal/object.py Propchange: branches/double_rotor/ ------------------------------------------------------------------------------ --- svnmerge-integrated (original) +++ svnmerge-integrated Mon Jan 27 18:54:40 2014 @@ -1,1 +1,1 @@ -/trunk:1-22045 +/trunk:1-22049 Modified: branches/double_rotor/lib/structure/internal/models.py URL: http://svn.gna.org/viewcvs/relax/branches/double_rotor/lib/structure/internal/models.py?rev=22050&r1=22049&r2=22050&view=diff ============================================================================== --- branches/double_rotor/lib/structure/internal/models.py (original) +++ branches/double_rotor/lib/structure/internal/models.py Mon Jan 27 18:54:40 2014 @@ -1,6 +1,6 @@ -############################################################################### -# # -# Copyright (C) 2008-2013 Edward d'Auvergne # +0############################################################################## +# # +# Copyright (C) 2008-2014 Edward d'Auvergne # # # # This file is part of the program relax (http://www.nmr-relax.com). # # # @@ -36,6 +36,16 @@ Here different models are defined as the same molecule but with different conformations. """ + + def __init__(self): + """Set up the class.""" + + # Execute the base class method. + super(ModelList, self).__init__() + + # The current model list (used for speed). + self.current_models = [] + def __repr__(self): """The string representation of the object. @@ -71,6 +81,9 @@ # Append an empty ModelContainer. self.append(ModelContainer(model_num)) + + # Update the current model list. + self.current_models.append(model_num) # Store the model indices. if not hasattr(self, 'model_indices'): Modified: branches/double_rotor/lib/structure/internal/object.py URL: http://svn.gna.org/viewcvs/relax/branches/double_rotor/lib/structure/internal/object.py?rev=22050&r1=22049&r2=22050&view=diff ============================================================================== --- branches/double_rotor/lib/structure/internal/object.py (original) +++ branches/double_rotor/lib/structure/internal/object.py Mon Jan 27 18:54:40 2014 @@ -2107,32 +2107,34 @@ raise RelaxError("Failure of the mapping of new molecule names, %s new molecule names verses %s molecules in the structural data." % (len(set_mol_name), len(data_matrix[0]))) # Test that the target models and structures are absent, and get the already existing model numbers. - current_models = [] - for i in range(len(self.structural_data)): - # Create a list of current models. - current_models.append(self.structural_data[i].num) + for i in range(len(set_model_num)): + # Merging flag is set, so skip the checks. + if merge: + continue + + # A new model, so no need to check. + if not set_model_num[i] in self.structural_data.current_models: + continue # Loop over the structures. - for j in range(len(self.structural_data[i].mol)): - if not merge and self.structural_data[i].num in set_model_num and self.structural_data[i].mol[j].mol_name in set_mol_name: + index = self.structural_data.current_models.index(set_model_num[i]) + for j in range(len(self.structural_data[index].mol)): + if self.structural_data[index].mol[j].mol_name in set_mol_name: raise RelaxError("The molecule '%s' of model %s already exists." % (self.structural_data[i].mol[j].mol_name, self.structural_data[i].num)) # Loop over the models. for i in range(len(set_model_num)): # The model doesn't currently exist. - if set_model_num[i] not in current_models: + if set_model_num[i] not in self.structural_data.current_models: # Create the model. self.structural_data.add_item(set_model_num[i]) - # Add the model number to the current_models list. - current_models.append(set_model_num[i]) - # Get the model. model = self.structural_data[-1] # Otherwise get the pre-existing model. else: - model = self.structural_data[current_models.index(set_model_num[i])] + model = self.structural_data[self.structural_data.current_models.index(set_model_num[i])] # Loop over the molecules. for j in range(len(set_mol_name)):