def __init__(self, working_folder="ase", clustering_method=None, altloc_method=None, maxnum_residues_in_cluster=20, charge_embedding=False, two_buffers=False, pdb_hierarchy=None, qm_engine_name=None, crystal_symmetry=None, clustering=True, qm_run=True, cif_objects=None, debug=False, charge_cutoff=8.0, save_clusters=False): self.charge_embedding = charge_embedding self.two_buffers = two_buffers self.crystal_symmetry = crystal_symmetry self.working_folder = os.path.abspath(working_folder) self.pdb_hierarchy = pdb_hierarchy self.charge_cutoff = charge_cutoff self.system_size = pdb_hierarchy.atoms_size() self.qm_engine_name = qm_engine_name self.clustering_method = clustering_method self.altloc_method = altloc_method self.debug = debug self.maxnum_residues_in_cluster = maxnum_residues_in_cluster self.save_clusters = save_clusters raw_records = pdb_hierarchy.as_pdb_string( crystal_symmetry=crystal_symmetry) self.charge_service = charges_class(raw_records=raw_records, ligand_cif_file_names=cif_objects) if (os.path.exists(self.working_folder) is not True): os.mkdir(self.working_folder) self.backbone_connections = fragment_utils.get_backbone_connections( self.pdb_hierarchy) self.get_altloc_molecular_indices() if (1): self.altloc_atoms = [ atom for atom in list(pdb_hierarchy.atoms()) if atom.pdb_label_columns()[4] != " " ] self.expansion = expand(pdb_hierarchy=self.pdb_hierarchy, crystal_symmetry=self.crystal_symmetry, select_within_radius=10.0) self.pdb_hierarchy_super = self.expansion.ph_super_sphere ## write expansion.pdb as the reference for capping self.expansion_file = "expansion.pdb" self.expansion.write_super_cell_selected_in_sphere( file_name=self.expansion_file) if (clustering): self.yoink_dat_path = os.path.join(qrefine, "plugin", "yoink", "dat") self.pyoink = PYoink( os.path.join(qrefine, "plugin", "yoink", "Yoink-0.0.1.jar")) self.qm_run = qm_run #t0 = time.time() self.set_up_cluster_qm()
def __init__( self, fragment_extracts=None, pdb_hierarchy=None, charge=None, qm_engine_name=None, qm_addon=None, qm_addon_method=None, file_name="./ase/tmp_ase.pdb", crystal_symmetry=None, clustering=False, # charge_service = None, cif_objects=None, # change to quantum phil scope !!!! method='rhf', basis="sto-3g", memory=None, nproc=None, ): self.fragment_extracts = fragment_extracts self.method = method self.basis = basis self.memory = memory self.nproc = nproc self.qm_addon = qm_addon self.qm_addon_method = qm_addon_method self.pdb_hierarchy = pdb_hierarchy self.qm_engine_name = qm_engine_name self.file_name = file_name self.working_folder = os.path.split(self.file_name)[0] + "/" if (os.path.exists(self.working_folder) is not True): os.mkdir(self.working_folder) if (charge is None and clustering is False): #raw_records = pdb_hierarchy.as_pdb_string(crystal_symmetry=crystal_symmetry) #cc = charges_class(raw_records=raw_records) #self.charge = cc.get_total_charge() #@Nigel raw_records = pdb_hierarchy.as_pdb_string( crystal_symmetry=crystal_symmetry) charge_service = charges_class(raw_records=raw_records, cif_objects=cif_objects) self.charge = charge_service.get_total_charge() else: self.charge = charge self.clustering = clustering self.qm_engine = self.create_qm_engine() self.qm_engine.command = self.qm_engine.get_command() self.system_size = self.pdb_hierarchy.atoms_size()
def get_fragment_hierarchies_and_charges(self): def pdb_hierarchy_select(atoms_size, selection): selection_array = flex.bool(atoms_size, False) for item in selection: if (item <= atoms_size): selection_array[item - 1] = True return selection_array self.fragment_selections = [] self.fragment_super_selections = [] self.fragment_charges = [] self.cluster_selections = [] self.buffer_selections = [] for i in range(len(self.fragment_super_atoms)): fragment_selection = pdb_hierarchy_select( self.pdb_hierarchy.atoms_size(), self.fragment_super_atoms[i]) ## QM part is fragment_super fragment_super_selection = pdb_hierarchy_select( self.pdb_hierarchy_super.atoms_size(), self.fragment_super_atoms[i]) fragment_super_hierarchy = self.pdb_hierarchy_super.select( fragment_super_selection) if (self.debug): fragment_super_hierarchy.write_pdb_file(file_name=str(i) + "-origin-cs.pdb") fragment_super_hierarchy.write_pdb_file( file_name=str(i) + ".pdb", crystal_symmetry=self.expansion.cs_box) charge_hierarchy = completion.run( pdb_hierarchy=fragment_super_hierarchy, crystal_symmetry=self.expansion.cs_box, model_completion=False, original_pdb_filename=self.expansion_file) raw_records = charge_hierarchy.as_pdb_string( crystal_symmetry=self.expansion.cs_box) if (1): charge_hierarchy.write_pdb_file( file_name=str(i) + "_capping.pdb", crystal_symmetry=self.expansion.cs_box) self.charge_service.update_pdb_hierarchy( charge_hierarchy, self.expansion.cs_box, ) #TODO: do not why self.charge_service could not right charge #charge = self.charge_service.get_total_charge() charge = charges_class(pdb_filename=str(i) + "_capping.pdb").get_total_charge() #the capping pdb file causes problem for tests, remove it os.remove(str(i) + "_capping.pdb") self.fragment_super_selections.append(fragment_super_selection) # self.fragment_selections.append(fragment_selection) self.fragment_charges.append(charge) cluster_selection = pdb_hierarchy_select( self.pdb_hierarchy.atoms_size(), self.cluster_atoms[i]) self.cluster_selections.append(cluster_selection) s = fragment_selection == cluster_selection buffer_selection = fragment_selection.deep_copy().set_selected( s, False) self.buffer_selections.append(buffer_selection) if (self.debug): fragment_super_hierarchy.write_pdb_file( file_name=str(i) + "_frag.pdb", crystal_symmetry=self.expansion.cs_box) cluster_pdb_hierarchy = self.pdb_hierarchy.select( cluster_selection) cluster_pdb_hierarchy.write_pdb_file( file_name=str(i) + "_cluster.pdb", crystal_symmetry=self.expansion.cs_box)