Debian Codegraph @

auxil/catcheck/catcheck.cc

raw
1
2 #include <unistd.h>
3 #include <iostream>
4 #include "catcheck.hh"
5 #include <algorithm> // for sort
6
7 int main(int argc, char **argv) {
8
9 if (argc > 1) {
10 std::string filename = argv[1];
11 mmdb::Manager *mol = get_mol(filename);
12 if (mol) {
13 water_coordination_check(mol, 3.2);
14 }
15 } else {
16 std::cout << "Usage: " << argv[0] << " <pdb-file-name>"
17 << std::endl;
18 }
19 return 0;
20 }
21
22 mmdb::Manager *get_mol(const std::string &filename) {
23
24 mmdb::Manager *MMDBManager = new mmdb::Manager();
25 int err = MMDBManager->ReadCoorFile((char *)filename.c_str());
26 if (err) {
27 std::cout << "Error reading " << filename << std::endl;
28 delete MMDBManager;
29 MMDBManager = 0;
30 }
31 return MMDBManager;
32 }
33
34
35 bool
36 contact_info_t::contacts_less(const contact_info_t &a, const contact_info_t &b) {
37 return (b.contact_indices.size() < a.contact_indices.size());
38 }
39
40 void water_coordination_check(mmdb::Manager *mol, float max_dist) {
41
42 // Make 2 atom selections,
43 // 1) the whole molecule
44 // 2) the waters
45 // Then do a distance check between them:
46
47 mmdb::PAtom *whole_protein_atom_sel;
48 int SelectionHandle = mol->NewSelection();
49 mol->SelectAtoms (SelectionHandle, 0, "*",
50 mmdb::ANY_RES, // starting resno, an int
51 "*", // any insertion code
52 mmdb::ANY_RES, // ending resno
53 "*", // ending insertion code
54 "*", // any residue name
55 "*", // atom name
56 "*", // elements
57 "*" // alt loc.
58 );
59 int nSelAtoms_all;
60 mol->GetSelIndex(SelectionHandle, whole_protein_atom_sel, nSelAtoms_all);
61
62 mmdb::PAtom *waters_atom_sel = 0;
63 int SelectionHandle_waters = mol->NewSelection();
64 mol->SelectAtoms (SelectionHandle_waters, 0, "*",
65 mmdb::ANY_RES, // starting resno, an int
66 "*", // any insertion code
67 mmdb::ANY_RES, // ending resno
68 "*", // ending insertion code
69 "WAT,HOH", // any residue name
70 "*", // atom name
71 "*", // elements
72 "*" // alt loc.
73 );
74 int nSelAtoms_waters;
75 mol->GetSelIndex(SelectionHandle_waters, waters_atom_sel, nSelAtoms_waters);
76
77 std::cout << "All Atoms: " << nSelAtoms_all << " waters: " << nSelAtoms_waters
78 << std::endl;
79
80 mmdb::mat44 my_matt;
81 for (int i=0; i<4; i++)
82 for (int j=0; j<4; j++)
83 my_matt[i][j] = 0.0;
84 for (int i=0; i<4; i++) my_matt[i][i] = 1.0;
85 long i_contact_group = 1;
86 mmdb::Contact *contact = NULL;
87 int ncontacts;
88
89 mol->SeekContacts(whole_protein_atom_sel, nSelAtoms_all,
90 waters_atom_sel, nSelAtoms_waters,
91 0.01, max_dist,
92 0,
93 contact, ncontacts, 0, &my_matt, i_contact_group);
94
95 std::vector<contact_info_t> atom_contacts(nSelAtoms_waters);
96 for (unsigned int i=0; i<atom_contacts.size(); i++) {
97 atom_contacts[i].this_index = i;
98 }
99
100 for (int i=0; i< ncontacts; i++) {
101 mmdb::Atom *at = waters_atom_sel[contact[i].id2];
102 mmdb::Atom *pat = whole_protein_atom_sel[contact[i].id1];
103 std::string p_ele(pat->element);
104 std::string w_ele(at->element);
105 if (p_ele != " C") {
106 std::cout << "Accepting contact to atom with index "
107 << contact[i].id2 << " " << at->GetAtomName()
108 << at->GetResName() << " " << at->GetSeqNum() << " "
109 << at->GetChainID() << " :" << w_ele << ": by atom "
110 << pat->GetAtomName() << " " << pat->GetResName() << " "
111 << pat->GetSeqNum() << " " << pat->GetChainID() << " :"
112 << p_ele << ": " << contact[i].id1 << std::endl;
113 atom_contacts[contact[i].id2].contact_indices.push_back(contact[i].id1);
114 } else {
115 std::cout << "###Reject contact to atom with index "
116 << contact[i].id2 << " " << at->GetAtomName()
117 << at->GetResName() << " " << at->GetSeqNum() << " "
118 << at->GetChainID() << " :" << w_ele << ": by atom "
119 << pat->GetAtomName() << " " << pat->GetResName() << " "
120 << pat->GetSeqNum() << " " << pat->GetChainID() << " :"
121 << p_ele << ": " << contact[i].id1 << std::endl;
122 }
123 }
124 std::sort(atom_contacts.begin(), atom_contacts.end(), contact_info_t::contacts_less);
125 std::cout << "sorted" << std::endl;
126
127 for (unsigned int i=0; i<atom_contacts.size(); i++) {
128 std::cout << "index: " << atom_contacts[i].this_index << std::endl;
129 mmdb::Atom *at = waters_atom_sel[atom_contacts[i].this_index];
130 std::cout << "at: " << at << std::endl;
131 std::cout << atom_contacts[i].this_index << " " << at->GetResName() << " "
132 << at->GetSeqNum() << " " << at->GetChainID() << " has "
133 << atom_contacts[i].contact_indices.size() << " contacts\n";
134 for (unsigned int j=0; j<atom_contacts[i].contact_indices.size(); j++) {
135 mmdb::Atom *pat = whole_protein_atom_sel[atom_contacts[i].contact_indices[j]];
136 std::string p_ele(pat->element);
137 std::cout << " "
138 << pat->GetAtomName() << " " << pat->GetResName() << " "
139 << pat->GetSeqNum() << " " << pat->GetChainID() << " :"
140 << p_ele << ":" << std::endl;
141 }
142 }
143 }