/* high-res/high-res.cc * * Copyright 2003, 2004 by Paul Emsley, The University of York * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or (at * your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA * 02110-1301, USA */ #include #include #include "coords/mmdb-extras.hh" // for atom_selection_container_t used in coot-close #include "coords/mmdb.hh" // for formatting of mmdb::Atom #include "coords/coot-close.hh" #include "coot-utils/coot-coord-utils.hh" #include "coot-atom-graph.hh" #include "mini-mol/mini-mol-utils.hh" #include "high-res.hh" coot::high_res::high_res(const coot::minimol::molecule &mol) { // first get the atom at the "middle" of the mol. Let's get the // "most connected" atom (i.e. the atom with the most contacts with // a radius of 15A). // // Also return the mmdb_manager that we used to find this. // std::pair middle_pos = get_middle_pos(mol); clipper::Coord_orth target_pos = middle_pos.first; fill_globular_protein(mol, middle_pos.first, middle_pos.second); // clear up middle_pos.second here make_trees(); } coot::high_res::high_res(const coot::minimol::molecule &mol, int iflag) { std::pair middle_pos = get_middle_pos(mol); fill_globular_protein_by_fragments(mol, middle_pos.first, middle_pos.second); delete middle_pos.second; } coot::high_res::high_res(const coot::minimol::molecule &mol, const clipper::Coord_orth &given_centre) { std::pair middle_pos = get_middle_pos(mol); fill_globular_protein_by_fragments(mol, given_centre, middle_pos.second); delete middle_pos.second; } void coot::high_res::output_pdb(const std::string &filename) const { globular_molecule.write_file(filename, 20.0); } std::pair coot::high_res::get_middle_pos(const coot::minimol::molecule &minimol_mol) const { std::pair r; long i_contact_group = 1; mmdb::Manager *mol = minimol_mol.pcmmdbmanager(); r.second = mol; mmdb::Contact *pscontact = NULL; int n_contacts = -1; float min_dist = 1.0; float max_dist = 15.0; mmdb::mat44 my_matt; for (int i=0; i<4; i++) for (int j=0; j<4; j++) my_matt[i][j] = 0.0; for (int i=0; i<4; i++) my_matt[i][i] = 1.0; atom_selection_container_t asc = make_asc(mol); int err = mol->GetTMatrix(my_matt, 0, 0, 0, 0); if (err != mmdb::SYMOP_Ok) { std::cout << "!! Warning:: No symmetry available for this molecule" << std::endl; } else { mol->SeekContacts(asc.atom_selection, asc.n_selected_atoms, asc.atom_selection, asc.n_selected_atoms, min_dist, max_dist, // min, max distances 0, // seqDist 0 -> in same res also pscontact, n_contacts, 0, &my_matt, i_contact_group); std::cout << "INFO:: There were " << n_contacts << " contacts. " << std::endl; std::vector contact_atom(asc.n_selected_atoms); for (int i=0; i most_contacts) { most_contacts_index = i; most_contacts = contact_atom[i]; } } if (most_contacts >= 0) { mmdb::Atom *at = asc.atom_selection[most_contacts_index]; r.first = clipper::Coord_orth(at->x, at->y, at->z); } delete [] pscontact; std::cout << "INFO:: get_middle_pos: returns " << r.first.format() << " with " << asc.n_selected_atoms << " atoms " << std::endl; } return r; } // needed? #include "coords/coot-close.hh" void coot::high_res::fill_globular_protein(const coot::minimol::molecule &mol, const clipper::Coord_orth &target_pos_in, mmdb::Manager *mmdb_mol) { clipper::Coord_orth sum_atoms = target_pos_in; clipper::Coord_orth target_pos = target_pos_in; // now a bit of jiggery pokery // Lets add 20 atoms at the target_pos; sum_atoms = clipper::Coord_orth(20.0*target_pos.x(), 20.0*target_pos.y(), 20.0*target_pos.z()); double n_atoms = 20; clipper::Coord_orth t; globular_molecule.set_cell_symm(mol); for (unsigned int ifrag=0; ifrag > contact_indices(asc.n_selected_atoms); int nsymops = 0; if (mol->GetNumberOfSymOps() == 0) { std::cout << "WARNING:: no symmetry available! no connections!\n"; } else { mmdb::realtype cell[6]; mmdb::realtype vol; int orthcode; mol->GetCell(cell[0], cell[1], cell[2], cell[3], cell[4], cell[5], vol, orthcode); std::cout << " Spacegroup: " << mol->GetSpaceGroup() << "\n"; std::cout << " Cell: " << cell[0] << " " << cell[1] << " " << cell[2] << " " << cell[3] << " " << cell[4] << " " << cell[5] << " " << "\n"; std::cout << "Here there are " << mol->GetNumberOfSymOps() << " symmetry operators\n"; std::cout << "Finding contacts for " << asc.n_selected_atoms << " atoms\n"; mmdb::mat44 my_matt; for (int i=0; i<4; i++) for (int j=0; j<4; j++) my_matt[i][j] = 0.0; for (int i=0; i<4; i++) my_matt[i][i] = 1.0; for (int ix = -1; ix < 2; ix++) { for (int iy = -1; iy < 2; iy++) { for (int iz = -1; iz < 2; iz++) { for (int isym = 0; isym < mol->GetNumberOfSymOps(); isym++) { // std::cout << "Round: " << isym << " " // << ix << " " << iy << " " << iz << std::endl; int err = mol->GetTMatrix(my_matt, isym, ix, iy, iz); nsymops++; if (err != 0) { std::cout << "WARNING:: something BAD with mmdb::CMMDBCryst.GetTMatrix\n"; } else { pscontact = NULL; mol->SeekContacts(asc.atom_selection, asc.n_selected_atoms, asc.atom_selection, asc.n_selected_atoms, min_dist, max_dist, // min, max distances 0, // seqDist 0 -> in same res also pscontact, n_contacts, 0, &my_matt, i_contact_group); // for (int i=0; i<4; i++) // for (int j=0; j<4; j++) // if (fabs(my_matt[i][j]) < 0.001) // my_matt[i][j] = 0.0; // clipper::Mat33 clipper_mat(my_matt[0][0], my_matt[0][1], my_matt[0][2], // my_matt[1][0], my_matt[1][1], my_matt[1][2], // my_matt[2][0], my_matt[2][1], my_matt[2][2]); // clipper::Coord_orth cco(my_matt[0][3], my_matt[1][3], my_matt[2][3]); // clipper::RTop_orth rtop(clipper_mat, cco); // std::cout << "rtop: \n" << rtop.format() << "\n"; // Now we need to do tree bond indexing like we do for mgtree elsewhere. // int in1, in2; for (int i=0; i coords; for (int iat=0; iatx, asc.atom_selection[iat]->y, asc.atom_selection[iat]->z)); // std::cout << "There are " << contact_indices.size() // << " atoms "<< std::endl; // for(int i=0; iSeekContacts(asc.atom_selection, asc.n_selected_atoms, asc.atom_selection, asc.n_selected_atoms, min_dist, max_dist, 0, // seqDist contact, ncontacts); for (int i=0; i<10; i++) std::cout << " " << asc.atom_selection[i] << std::endl; std::cout << "found " << ncontacts << " contacts" << std::endl; if (ncontacts > 0) { // mark each atom with a group (cluster) id. Initially set the // group id to -1 (unset). int uddhandle = asc.mol->RegisterUDInteger(mmdb::UDR_ATOM, "buccaneer filter group"); for (int i=0; iPutUDData(uddhandle, -1); if (istat == mmdb::UDDATA_WrongUDRType) { std::cout << "ERROR:: mmdb:UDDATA_WrongUDRType in " << "buccafilter" << std::endl; } } // OK now every atom has a group marker - currently unset. // // now something tricky. We need to find neighbours of this // atom that has the same atom name as this atom... and // neighbours of that neighbours until there are no more // neighbours of neighbours that are unmarked. // // neighbours is a vector: for each atom we have a vector that // is a list of the atoms to which this atom has neighbours // std::vector > neighbours(asc.n_selected_atoms); for (int ic=0; ic< ncontacts; ic++) neighbours[ contact[ic].id1 ].push_back(contact[ic].id2); int igroup = 0; int ierr; int ic; for (int iat=0; iatGetUDData(uddhandle, ic); if (ierr == mmdb::UDDATA_Ok) { if (ic == -1) { char *at_name = asc.atom_selection[iat]->name; std::string atom_name(at_name); mark_neighbours(iat, igroup, at_name, neighbours, asc.atom_selection, uddhandle); igroup++; } } } std::cout << " Found " << igroup << " groups " << std::endl; // // // So every atom is marked now. // Let's make the groups. // std::vector > groups(igroup); for (int iat=0; iatGetUDData(uddhandle, igroup); groups[igroup].push_back(iat); } // replace globular_molecule with the result of the filtering globular_molecule = filter_on_groups(groups, asc.mol, asc.atom_selection, asc.n_selected_atoms); } delete mol; // give back the pcmmdbmanager memory std::cout << "Done buccafilter filtering" << std::endl; } void coot::high_res::buccafilter() { // Change globular_molecule // // First Lets make a molecule that has fragments that are sorted by // length. std::vector fragments = globular_molecule.fragments; std::sort(fragments.begin(), fragments.end(), fragment_sorter); // DEBUGGING // for (int ifrag=0; ifrag 0) { // a_min_res_no = ir; // break; // } // } // std::cout << " fragment " << ifrag << " has " // << fragments[ifrag].residues.size() // << " residues with max_residue_number: " // << fragments[ifrag].max_residue_number() // << " range length " << fragments[ifrag].max_residue_number() - a_min_res_no // << std::endl; // } // Actually, we don't need to sort by length, we can use the order // that the fragments came in as the sorted order - Kevin says that // they are sorted by density fit (likelihood, perhaps). // // globular_molecule.fragments = fragments; // globular_molecule.write_file("fragmented.pdb"); // debug mmdb::Manager *mol = globular_molecule.pcmmdbmanager(); atom_selection_container_t asc = make_asc(mol); mmdb::Contact *contact = NULL; int ncontacts; mmdb::realtype min_dist = 0.0; mmdb::realtype max_dist = 2.0; std::cout << "INFO asc has " << asc.n_selected_atoms << " selected atoms" << std::endl; asc.mol->SeekContacts(asc.atom_selection, asc.n_selected_atoms, asc.atom_selection, asc.n_selected_atoms, min_dist, max_dist, 0, // seqDist contact, ncontacts); std::cout << "found " << ncontacts << " contacts" << std::endl; if (ncontacts > 0) { for (int i=0; i<10; i++) std::cout << " " << asc.atom_selection[i] << std::endl; std::map chain_numbers; int imod = 1; mmdb::Model *model_p = asc.mol->GetModel(imod); mmdb::Chain *chain_p; int nchains = model_p->GetNumberOfChains(); std::cout << "mol has " << nchains << " chains " << std::endl; for (int ich=0; ichGetChain(ich); chain_numbers[chain_p] = ich; } int ich1; int ich2; int uddhandle = asc.mol->RegisterUDInteger(mmdb::UDR_ATOM, "delete me flag"); for (int iat=0; iatPutUDData(uddhandle, 0); for (int ic=0; ic< ncontacts; ic++) { mmdb::Chain *chain1 = asc.atom_selection[contact[ic].id1]->GetChain(); mmdb::Chain *chain2 = asc.atom_selection[contact[ic].id2]->GetChain(); if (chain1 != chain2) { ich1 = chain_numbers[chain1]; ich2 = chain_numbers[chain2]; if (ich2 > ich1) { // delete asc.atom_selection[contact[ic].id2]->PutUDData(uddhandle, 1); } } } int idelete = 0; for (int iat=0; iatGetUDData(uddhandle, idelete); if (idelete == 1) { delete asc.atom_selection[iat]; asc.atom_selection[iat] = 0; } } asc.mol->FinishStructEdit(); asc.mol->WritePDBASCII("asc.mol.pdb"); } coot::minimol::molecule mmol(asc.mol); mmol.write_file("mmol.pdb", 20.0); globular_molecule = mmol; delete asc.mol; // give back the memory } void coot::high_res::add_os() { for (unsigned int ifrag=0; ifrag 0) { if (globular_molecule[ifrag][ires].atoms.size() > 0) { // test for non-existance of O short int o_exists_in_residue = 0; for (unsigned int iat=0; iat p = coot::o_position(globular_molecule[ifrag][ires], globular_molecule[ifrag][ires+1]); // std::cout << "::::::::: o p returns " << p.first << " " // << p.second.format() << std::endl; if (p.first) { coot::minimol::atom o(" O ", " O", p.second, "", 30.0); globular_molecule[ifrag][ires].addatom(o); } } } } } } } void coot::high_res::add_cbetas() { // Let's use a coot-utils function to find the cb position, since // we will add cbetas in more than "high-res" models. // for (unsigned int ifrag=0; ifrag 0) { // test for non-existance of CBETA short int cbeta_exists_in_residue = 0; for (unsigned int iat=0; iat p = coot::cbeta_position(globular_molecule[ifrag][ires]); if (p.first == 1) globular_molecule[ifrag][ires].addatom(" CB ", " C", p.second, "", 1.0, 30.0); } } } } } // static bool coot::high_res::fragment_sorter(const coot::minimol::fragment &a, const coot::minimol::fragment &b) { int a_min_res_no = 0; int b_min_res_no = 0; for (unsigned int ir=0; ir 0) { a_min_res_no = ir; break; } } for (unsigned int ir=0; ir 0) { b_min_res_no = ir; break; } } return (a.max_residue_number() - a_min_res_no) > (b.max_residue_number() - b_min_res_no); } // Tinker with the UDD of the atom selection // void coot::high_res::mark_neighbours(int iatom, int igroup, const std::string &atom_name, const std::vector > &neighbours, mmdb::PPAtom atom_selection, int uddhandle) { int ig; atom_selection[iatom]->GetUDData(uddhandle, ig); if (ig == -1) { std::string this_atom_name = atom_selection[iatom]->name; if (this_atom_name == atom_name) { atom_selection[iatom]->PutUDData(uddhandle, igroup); std::vector n = neighbours[iatom]; int ns = n.size(); for (int in=0; inx, at->y, at->z); sum += pt; } double frac = 1.0/double(n_grp_ats); clipper::Coord_orth new_sum(0.0, 0.0, 0.0); clipper::Coord_orth mean_pt(sum.x()*frac, sum.y()*frac, sum.z()*frac); // double dist_crit = 0.5; // A int n_group_within_lim = 0; for (int iat=0; iatx, at->y, at->z); // double d = clipper::Coord_orth::length(mean_pt, pt); // if (d < dist_crit) { n_group_within_lim++; new_sum += pt; // } } if (groups[igroup].size() > 10) { for (unsigned int iat=0; iatx << " " << atom_selection[groups[igroup][iat]]->y << " " << atom_selection[groups[igroup][iat]]->z << ")" << std::endl; } } if (n_group_within_lim > 0) { frac = 1.0/double(n_group_within_lim); clipper::Coord_orth av_pt(new_sum.x()*frac, new_sum.y()*frac, new_sum.z()*frac); mmdb::Atom *speced_at = atom_selection[groups[igroup][0]]; std::string atom_name(speced_at->name); std::string atom_element(speced_at->element); int resno = speced_at->GetSeqNum(); std::string chain_id(speced_at->GetChainID()); int ifrag = m.fragment_for_chain(chain_id); coot::minimol::atom atom(atom_name, atom_element, av_pt, "", 30.0); // std::cout << "DEBUG:: resno is " << resno << std::endl; m[ifrag][resno].name = "ALA"; m[ifrag][resno].seqnum = resno; m[ifrag][resno].addatom(atom); } else { std::cout << "OOps! No unfiltered atoms left for " << atom_selection[groups[igroup][0]] << std::endl; } } return m; } // Tom does not discuss // // How to convert from (asymmetric unit?) map peaks to nodes // (potential atoms). i.e. how do we apply symmetry to put the nodes // next to each other rather than being in the wrong asymmetric unit. // // Multiple conformations // // Longest path // // stitching together fragments // // stitching together wrong asymmetric unit fragments // // sequence assignement // // I do like the distortion score though. //