Exemplo n.º 1
0
 def get_element(self, element_id):
     """
     We must override this guy. In this case the behaviour is to obtain a 
     full Prody structure.
     """
     element_coordinates = self.structure_ensemble.getCoordsets()[element_id]
     structure = self.structure_ensemble.copy()
     removeAllCoordsetsFromStructure(structure)
     structure.addCoordset(element_coordinates)
     return structure
Exemplo n.º 2
0
 def get_element(self, element_id):
     """
     We must override this guy. In this case the behaviour is to obtain a 
     full Prody structure.
     """
     element_coordinates = self.structure_ensemble.getCoordsets(
     )[element_id]
     structure = self.structure_ensemble.copy()
     removeAllCoordsetsFromStructure(structure)
     structure.addCoordset(element_coordinates)
     return structure
Exemplo n.º 3
0
 def get_elements(self, elements_list):
     """
     When we work with ensembles it is better to return a single prody ensemble with all
     the elements we want.
     Returns a copy! Modifying it does not modify the stored structure.
     """
     element_coordinates = self.structure_ensemble.getCoordsets()[elements_list]
     structure = self.structure_ensemble.copy()
     removeAllCoordsetsFromStructure(structure)
     for coordset in element_coordinates:
         structure.addCoordset(coordset)
     return structure
Exemplo n.º 4
0
 def get_elements(self, elements_list):
     """
     When we work with ensembles it is better to return a single prody ensemble with all
     the elements we want.
     Returns a copy! Modifying it does not modify the stored structure.
     """
     element_coordinates = self.structure_ensemble.getCoordsets(
     )[elements_list]
     structure = self.structure_ensemble.copy()
     removeAllCoordsetsFromStructure(structure)
     for coordset in element_coordinates:
         structure.addCoordset(coordset)
     return structure
Exemplo n.º 5
0
    def load_data_from_source(self, source):
        """
        Loads a structure file (pdb or dcd) and updates source info.

        :param source: Is a DataSource object with one of this sets of keywords:
        
        - For 'pdb' files:

            {
                "source": ... ,
                "base_selection": ...
            }

        Where 'file' contains the path of the pdb file we want to load.

        - For 'dcd' files:

            {
                "source": ...,
                "atoms_source": ...,
                "base_selection": ...
            }

        Where 'file' contains the path of the 'dcd' file we want to load and 'atoms_file' the source of the pdb file containing
        the atomic information.

        In both cases 'base_selection' is a Prody selection string that performs an initial selection of the atoms. This is
        useful when we want to load more than one file with different number of atoms and its goal is to allow the selection
        of the common atoms. It is up to the user to maintain a 1 to 1 mapping between the atoms of each of the files.

        The source object will be enriched with some extra information from the loaded structure ensemble.

        :return: Prody's structure object with the loaded ensemble
        """
        _, ext = os.path.splitext(source.get_path())
        
        if ext == ".dcd":
            structure = prody.parsePDB(source.get_info("atoms_source"))
            # Leave only atomic information
            removeAllCoordsetsFromStructure(structure)
            dcd_data = prody.DCDFile(source.get_path())
            coordsets = dcd_data.getCoordsets()
            # Add all coordsets to atomic information
            for coordset in coordsets:
                structure.addCoordset(coordset)
            
        elif ext == ".pdb":
            structure = prody.parsePDB(source.get_path())
        else:
            print "[ERROR][ProteinStructureEnsembleData::get_structure] pyProCT does not know hot to load the file %s (unknown extension '%s')"%(source.get_path(),ext)
            exit()
        
        if source.has_info("base_selection"):
            structure = structure.select(source.get_info("base_selection")).copy()
            if structure is None:
                common.print_and_flush("[ERROR ProteinStructureEnsembleData::get_structure] Improductive base selection (%s). Exiting...\n"%source.get_info("base_selection"))
                exit()

        source.add_info("number_of_conformations", structure.numCoordsets())
        source.add_info("number_of_atoms", structure.numAtoms())
        
        self.model_numbers.extend(self.get_model_numbers(source, structure.numCoordsets()))
        self.model_remarks.extend(self.get_remarks(source, structure.numCoordsets()))
        
        return  structure, structure.numCoordsets()
Exemplo n.º 6
0
 def test_removeAllCoordsetsFromStructure(self):
     input = StringIO.StringIO(switched_pdb_data)
     pdb_structure = prody.parsePDBStream(input)
     removeAllCoordsetsFromStructure(pdb_structure)
     self.assertEqual(pdb_structure.getCoordsets(),None)
Exemplo n.º 7
0
    def load_data_from_source(self, source):
        """
        Loads a structure file (pdb or dcd) and updates source info.

        :param source: Is a DataSource object with one of this sets of keywords:
        
        - For 'pdb' files:

            {
                "source": ... ,
                "base_selection": ...
            }

        Where 'file' contains the path of the pdb file we want to load.

        - For 'dcd' files:

            {
                "source": ...,
                "atoms_source": ...,
                "base_selection": ...
            }

        Where 'file' contains the path of the 'dcd' file we want to load and 'atoms_file' the source of the pdb file containing
        the atomic information.

        In both cases 'base_selection' is a Prody selection string that performs an initial selection of the atoms. This is
        useful when we want to load more than one file with different number of atoms and its goal is to allow the selection
        of the common atoms. It is up to the user to maintain a 1 to 1 mapping between the atoms of each of the files.

        The source object will be enriched with some extra information from the loaded structure ensemble.

        :return: Prody's structure object with the loaded ensemble
        """
        _, ext = os.path.splitext(source.get_path())
        
        if ext == ".dcd":
            structure = prody.parsePDB(source.get_info("atoms_source"))
            # Leave only atomic information
            removeAllCoordsetsFromStructure(structure)
            dcd_data = prody.DCDFile(source.get_path())
            coordsets = dcd_data.getCoordsets()
            # Add all coordsets to atomic information
            for coordset in coordsets:
                structure.addCoordset(coordset)
            
        elif ext == ".pdb":
            structure = prody.parsePDB(source.get_path())
        else:
            print "[ERROR][ProteinStructureEnsembleData::get_structure] pyProCT does not know how to load the file %s (unknown extension '%s')"%(source.get_path(),ext)
            exit()
        
        if source.has_info("base_selection"):
            structure = structure.select(source.get_info("base_selection")).copy()
            if structure is None:
                common.print_and_flush("[ERROR ProteinStructureEnsembleData::get_structure] Improductive base selection (%s). Exiting...\n"%source.get_info("base_selection"))
                exit()
        
        print "Loaded %d conformations with %d atoms from %s."%(structure.numCoordsets(), 
                                                                structure.numAtoms(),
                                                                source.get_path())
#         prody.writePDB("%s_test"%source.get_path(), structure, csets= [1])

        source.add_info("number_of_conformations", structure.numCoordsets())
        source.add_info("number_of_atoms", structure.numAtoms())
        
        self.model_numbers.extend(self.get_model_numbers(source, structure.numCoordsets()))
        self.model_remarks.extend(self.get_remarks(source, structure.numCoordsets()))
        
        return  structure, structure.numCoordsets()
Exemplo n.º 8
0
 def test_removeAllCoordsetsFromStructure(self):
     input = StringIO.StringIO(switched_pdb_data)
     pdb_structure = prody.parsePDBStream(input)
     removeAllCoordsetsFromStructure(pdb_structure)
     self.assertEqual(pdb_structure.getCoordsets(), None)