def calculate(cls, data_handler, matrix_params):
        """
        :param parameters: a ProtocolParameters object with at least one "matrices" 
        and "combination" attributes. 
         
        Inside the "matrices" object any type of "matrix" object can be defined. The 
        attribute id would be its id in the "combination" clause.
         
        Ex:
        "matrix":{
            "method":"matrix::combination",
            "parameters":{
                "matrices":{
                    "loaded_matrix":{
                        "method": "matrix::load",
                        "parameters": {
                            ...
                        }
                    },
                    "rmsd_matrix":{
                        "method": "rmsd:ensemble",
                        "parameters": {
                            "calculator_type": "QCP_OMP_CALCULATOR",
                            "fit_selection": "chain A",
                            ...
                        }
                    }
                },
                "combination": ["add",[]]
            }
         
        }
     
        @return: The created matrix.
        """
        forbidden = ["add", "sub", "mult"]
        matrices_descr = matrix_params.get_value("matrices", default_value={})
        matrices = {}
        operations = matrix_params.get_value("combination", default_value="")

        number_of_matrix_ids = len(matrices_descr.keys())
        if number_of_matrix_ids == 0:
            #raise
            pass
        else:
            #check that there are no forbidden ids
            for matrix_id in matrices_descr:
                if matrix_id in forbidden:
                    raise KeyError("Forbidden matrix id.")

        # Load the matrices
        for matrix_id in matrices_descr:
            print "Calculating %s" % (matrix_id)
            matrices[matrix_id] = MatrixCalculator.calculate(
                data_handler, matrices_descr[matrix_id])

        # Do the combination
        return combine(operations, matrices)
 def calculate(cls, data_handler, matrix_params):
     """
     :param parameters: a ProtocolParameters object with at least one "matrices" 
     and "combination" attributes. 
      
     Inside the "matrices" object any type of "matrix" object can be defined. The 
     attribute id would be its id in the "combination" clause.
      
     Ex:
     "matrix":{
         "method":"matrix::combination",
         "parameters":{
             "matrices":{
                 "loaded_matrix":{
                     "method": "matrix::load",
                     "parameters": {
                         ...
                     }
                 },
                 "rmsd_matrix":{
                     "method": "rmsd:ensemble",
                     "parameters": {
                         "calculator_type": "QCP_OMP_CALCULATOR",
                         "fit_selection": "chain A",
                         ...
                     }
                 }
             },
             "combination": ["add",[]]
         }
      
     }
  
     @return: The created matrix.
     """
     forbidden = ["add","sub","mult"]
     matrices_descr = matrix_params.get_value("matrices", default_value={})
     matrices = {}
     operations = matrix_params.get_value("combination", default_value="")
      
     number_of_matrix_ids = len(matrices_descr.keys()) 
     if number_of_matrix_ids == 0:
         #raise 
         pass
     else:
         #check that there are no forbidden ids
         for matrix_id in matrices_descr:
             if matrix_id in forbidden:
                 raise KeyError("Forbidden matrix id.")
      
     # Load the matrices
     for matrix_id in matrices_descr:
         print "Calculating %s"%(matrix_id)
         matrices[matrix_id] = MatrixCalculator.calculate(data_handler, 
                                                          matrices_descr[matrix_id])
          
     # Do the combination
     return combine(operations, matrices)
예제 #3
0
 def calc_matrix(cls, data_handler, matrix_parameters):
     return MatrixCalculator.calculate(data_handler, matrix_parameters)