Пример #1
0
def get_qm_file_name_and_pdb_hierarchy(fragment_extracts, index):
    fragment_selection = fragment_extracts.fragment_super_selections[index]
    fragment_hierarchy = fragment_extracts.pdb_hierarchy_super.select(
        fragment_selection)
    sub_working_folder = fragment_extracts.working_folder + "/" + str(
        index) + "/"
    if (not os.path.isdir(sub_working_folder)):
        os.mkdir(sub_working_folder)
    qm_pdb_file = sub_working_folder + str(index) + ".pdb"
    complete_qm_pdb_file = qm_pdb_file[:-4] + "_capping.pdb"
    if (fragment_extracts.debug):  ## for degugging
        fragment_hierarchy.write_pdb_file(
            file_name=qm_pdb_file,
            crystal_symmetry=fragment_extracts.expansion_cs)
    ph = completion.run(pdb_hierarchy=fragment_hierarchy,
                        crystal_symmetry=fragment_extracts.expansion_cs,
                        model_completion=False,
                        original_pdb_filename=fragment_extracts.expansion_file)
    ##for debugging
    if (fragment_extracts.debug):
        fragment_hierarchy.write_pdb_file(
            file_name=qm_pdb_file,
            crystal_symmetry=fragment_extracts.expansion_cs)
        ph.write_pdb_file(file_name=complete_qm_pdb_file)
    return os.path.abspath(complete_qm_pdb_file), ph
Пример #2
0
def write_cluster_and_fragments_pdbs(fragments, directory):
    # write current fragment and cluster PDBs into ./<directory>
    # makes a fresh(!) <directory>
    F = fragments
    if not F.save_clusters:
        return
    from shutil import rmtree
    cwd = os.getcwd()
    frag_dir = os.path.join(cwd, directory)
    expansion_file = os.path.join(cwd, fragments.expansion_file)
    if os.path.exists(frag_dir):
        rmtree(frag_dir)
    os.mkdir(frag_dir)
    os.chdir(frag_dir)
    for index, selection_fragment in enumerate(F.fragment_selections):
        cluster_selection = F.cluster_selections[index]
        frag_selection = F.fragment_super_selections[index]
        index_cluster = F.pdb_hierarchy.select(cluster_selection)
        index_frag = F.pdb_hierarchy_super.select(frag_selection)
        filename_cluster = "%s_cluster.pdb" % (index)
        filename_frag = "%s_frag.pdb" % (index)
        filename_capped = "%s_capped0.pdb" % (index)
        index_cluster.write_pdb_file(file_name=filename_cluster,
                                     crystal_symmetry=F.expansion_cs)
        index_frag.write_pdb_file(file_name=filename_frag,
                                  crystal_symmetry=F.expansion_cs)
        capped_hierarchy = completion.run(pdb_hierarchy=index_frag,
                                          crystal_symmetry=F.expansion_cs,
                                          model_completion=False,
                                          original_pdb_filename=expansion_file)
        #capped_hierarchy = F.fragment_capped_initial[index]
        capped_hierarchy.write_pdb_file(file_name=filename_capped,
                                        crystal_symmetry=F.expansion_cs)

    log = open('fragment_info.txt', 'w')
    print >> log, '~  # clusters  : ', len(F.cluster_atoms)
    print >> log, '~  list of atoms per cluster:'
    print >> log, '~   ', [len(x) for x in F.cluster_atoms]
    print >> log, '~  list of atoms per fragment:'
    print >> log, '~   ', [len(x) for x in F.fragment_super_atoms]
    os.chdir(cwd)
Пример #3
0
def get_qm_file_name_and_pdb_hierarchy(fragment_extracts, index):
    fragment_selection = fragment_extracts.fragment_super_selections[index]
    fragment_hierarchy = fragment_extracts.pdb_hierarchy_super.select(
        fragment_selection)
    sub_working_folder = fragment_extracts.working_folder + "/" + str(
        index) + "/"
    if (not os.path.isdir(sub_working_folder)):
        os.mkdir(sub_working_folder)
    qm_pdb_file = sub_working_folder + str(index) + ".pdb"
    complete_qm_pdb_file = qm_pdb_file[:-4] + "_capping.pdb"
    # if(fragment_extracts.debug):
    if (1):  # at least for now
        fragment_hierarchy.write_pdb_file(
            file_name=qm_pdb_file,
            crystal_symmetry=fragment_extracts.expansion_cs)
    # re-capping because geometry of the fragment has changed.
    ph = completion.run(pdb_hierarchy=fragment_hierarchy,
                        crystal_symmetry=fragment_extracts.expansion_cs,
                        model_completion=False,
                        original_pdb_filename=fragment_extracts.expansion_file)
    # we now want this file by default
    ph.write_pdb_file(file_name=complete_qm_pdb_file,
                      crystal_symmetry=fragment_extracts.expansion_cs)
    return os.path.abspath(complete_qm_pdb_file), ph
Пример #4
0
    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)