def build(cls, data_handler, matrix_creation_parameters): """ Generates a matrix with the method used in the handler creation. @param trajectory_handler: @param matrix_creation_parameters: @return: The created matrix. """ calculator_type = matrix_creation_parameters.get_value("calculator_type", default_value = "QTRFIT_OMP_CALCULATOR") calculator_options = matrix_creation_parameters.get_value("calculator_options", default_value = ProtocolParameters({"number_of_threads":8, "blocks_per_grid":8, "threads_per_block":32})) calculator_options = ProtocolParameters(calculator_options) structure = data_handler.get_data() fit_selection_coordsets = structure.getFittingCoordinates() calc_selection_coordsets = structure.getCalculationCoordinates() if calc_selection_coordsets is None: calculator = RMSDCalculator(calculatorType = calculator_type, fittingCoordsets = fit_selection_coordsets) else: symm_groups = [] if "symmetries" in matrix_creation_parameters: # Then prepare it to handle calculation symmetries # Description of equivalences must have the same number of atoms symm_groups = cls.process_symm_groups(matrix_creation_parameters, structure, calc_selection_coordsets) print "Using symmetries", symm_groups calculator = RMSDCalculator(calculatorType = calculator_type, fittingCoordsets = fit_selection_coordsets, calculationCoordsets = calc_selection_coordsets, calcSymmetryGroups = symm_groups) try: calculator.setNumberOfOpenMPThreads(calculator_options.get_value("number_of_threads", default_value = 8)) except KeyError: pass try: calculator.setCUDAKernelThreadsPerBlock(calculator_options.get_value("threads_per_block", default_value = 32), calculator_options.get_value("blocks_per_grid", default_value = 8)) except KeyError: pass rmsds = calculator.pairwiseRMSDMatrix() return CondensedMatrix(rmsds)
class WorkspaceHandler(Observable): def __init__(self, workspace_parameters, observer): super(WorkspaceHandler,self).__init__(observer) self.parameters = ProtocolParameters(workspace_parameters.get_value("parameters", default_value = ProtocolParameters({ "overwrite":True, "clear_after_exec":["tmp"] }))) self.data = { "results": os.path.join(workspace_parameters["base"], workspace_parameters.get_value("results", default_value="results")), "tmp" : os.path.join(workspace_parameters["base"], workspace_parameters.get_value("tmp", default_value= "tmp")), "clusters" : os.path.join(workspace_parameters["base"], workspace_parameters.get_value("clusters", default_value= "clusters")), "matrix" : os.path.join(workspace_parameters["base"], workspace_parameters.get_value("matrix", default_value= "matrix")) } def __getitem__(self,key): return self.data[key] def __str__(self): return json.dumps(self.data, sort_keys=False, indent=4, separators=(',', ': ')) def create_directories(self): """ Recreates the workspace structure. Removes the old location if necessary. """ self.notify("MSG","Creating workspace...") if self.parameters.get_value("overwrite", default_value = True) : self.clear_directories(self.data.keys()) for folder_key in self.data: scripts_common.create_directory(self.data[folder_key]) def clear_directories(self, directory_keys): """ Removes the directories given as parameters. @param directory_keys: The keys of the 'data' object which defined paths will be erased. """ for folder_key in directory_keys: folder_path = self.data[folder_key] if os.path.exists(folder_path): shutil.rmtree(folder_path) self.notify("MSG","Removing %s ..."%folder_path) # print "Removing %s ..."%folder_path def __enter__(self): self.create_directories() return self def __exit__(self, exception_type, exception_val, trace): self.clear_directories(self.parameters["clear_after_exec"])
def build(cls, data_handler, matrix_creation_parameters): """ Generates a matrix with the method used in the handler creation. @param trajectory_handler: @param matrix_creation_parameters: @return: The created matrix. """ calculator_type = matrix_creation_parameters.get_value( "calculator_type", default_value="QTRFIT_OMP_CALCULATOR") calculator_options = matrix_creation_parameters.get_value( "calculator_options", default_value=ProtocolParameters({ "number_of_threads": 8, "blocks_per_grid": 8, "threads_per_block": 32 })) calculator_options = ProtocolParameters(calculator_options) structure = data_handler.get_data() fit_selection_coordsets = structure.getFittingCoordinates() calc_selection_coordsets = structure.getCalculationCoordinates() if calc_selection_coordsets is None: calculator = RMSDCalculator( calculatorType=calculator_type, fittingCoordsets=fit_selection_coordsets) else: symm_groups = [] if "symmetries" in matrix_creation_parameters: # Then prepare it to handle calculation symmetries # Description of equivalences must have the same number of atoms symm_groups = cls.process_symm_groups( matrix_creation_parameters, structure, calc_selection_coordsets) print "Using symmetries", symm_groups calculator = RMSDCalculator( calculatorType=calculator_type, fittingCoordsets=fit_selection_coordsets, calculationCoordsets=calc_selection_coordsets, calcSymmetryGroups=symm_groups) try: calculator.setNumberOfOpenMPThreads( calculator_options.get_value("number_of_threads", default_value=8)) except KeyError: pass try: calculator.setCUDAKernelThreadsPerBlock( calculator_options.get_value("threads_per_block", default_value=32), calculator_options.get_value("blocks_per_grid", default_value=8)) except KeyError: pass rmsds = calculator.pairwiseRMSDMatrix() return CondensedMatrix(rmsds)
class WorkspaceHandler(Observable): def __init__(self, workspace_parameters, observer): super(WorkspaceHandler, self).__init__(observer) self.parameters = ProtocolParameters( workspace_parameters.get_value( "parameters", default_value=ProtocolParameters({"overwrite": True, "clear_after_exec": ["tmp"]}) ) ) self.data = { "results": os.path.join( workspace_parameters["base"], workspace_parameters.get_value("results", default_value="results") ), "tmp": os.path.join( workspace_parameters["base"], workspace_parameters.get_value("tmp", default_value="tmp") ), "clusters": os.path.join( workspace_parameters["base"], workspace_parameters.get_value("clusters", default_value="clusters") ), "matrix": os.path.join( workspace_parameters["base"], workspace_parameters.get_value("matrix", default_value="matrix") ), } def __getitem__(self, key): return self.data[key] def __str__(self): return json.dumps(self.data, sort_keys=False, indent=4, separators=(",", ": ")) def create_directories(self): """ Recreates the workspace structure. Removes the old location if necessary. """ self.notify("MSG", "Creating workspace...") if self.parameters.get_value("overwrite", default_value=True): self.clear_directories(self.data.keys()) for folder_key in self.data: scripts_common.create_directory(self.data[folder_key]) def clear_directories(self, directory_keys): """ Removes the directories given as parameters. @param directory_keys: The keys of the 'data' object which defined paths will be erased. """ for folder_key in directory_keys: folder_path = self.data[folder_key] if os.path.exists(folder_path): shutil.rmtree(folder_path) self.notify("MSG", "Removing %s ..." % folder_path) # print "Removing %s ..."%folder_path def __enter__(self): self.create_directories() return self def __exit__(self, exception_type, exception_val, trace): self.clear_directories(self.parameters["clear_after_exec"])