Skip to content

Commit

Permalink
Add a parser for acedrg atom types
Browse files Browse the repository at this point in the history
And add a test in test-molecules-container.
  • Loading branch information
pemsley committed Sep 15, 2024
1 parent 07f1b03 commit 643a206
Show file tree
Hide file tree
Showing 8 changed files with 156 additions and 3 deletions.
1 change: 1 addition & 0 deletions api/molecules-container-nanobind.cc
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ NB_MODULE(chapi, m) {
.def("generate_self_restraints",&molecules_container_t::generate_self_restraints)
.def("geometry_init_standard",&molecules_container_t::geometry_init_standard)
.def("get_active_atom",&molecules_container_t::get_active_atom)
.def("get_acedrg_atom_types",&molecules_container_t::get_acedrg_atom_types)
.def("get_atom",&molecules_container_t::get_atom, nb::rv_policy::reference)
.def("get_atom_using_cid",&molecules_container_t::get_atom_using_cid, nb::rv_policy::reference)
.def("get_bonds_mesh",&molecules_container_t::get_bonds_mesh)
Expand Down
28 changes: 28 additions & 0 deletions api/molecules-container.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5378,6 +5378,34 @@ molecules_container_t::get_gphl_chem_comp_info(const std::string &compound_id, i
return v;
}

//! get a list of atom names and their associated atedrg atom types
//!
//! @return a list of atom names and their associated atedrg atom types, return an empty list
//! on failure (atoms types are not in the dictionary or atom failure to look up the compound id)l
std::vector<std::pair<std::string, std::string> >
molecules_container_t::get_acedrg_atom_types(const std::string &compound_id, int imol_enc) const {

std::vector<std::pair<std::string, std::string> > v;
std::pair<bool, coot::dictionary_residue_restraints_t> r_p =
geom.get_monomer_restraints(compound_id, imol_enc);
if (r_p.first) {
const auto &restraints = r_p.second;
const auto &atom_info = restraints.atom_info;
for (unsigned int iat=0; iat<atom_info.size(); iat++) {
const auto &atom = atom_info[iat];
const auto &atom_id = atom.atom_id;
const auto &acedrg_atom_type = atom.acedrg_atom_type;
if (! acedrg_atom_type.empty()) {
auto pair = std::make_pair(atom_id, acedrg_atom_type);
v.push_back(pair);
}
}
}
return v;

}



//! export map molecule as glTF
void
Expand Down
6 changes: 6 additions & 0 deletions api/molecules-container.hh
Original file line number Diff line number Diff line change
Expand Up @@ -663,6 +663,12 @@ public:
//! return an empty vector on failure to find any such info.
std::vector<std::pair<std::string, std::string> > get_gphl_chem_comp_info(const std::string &compound_id, int imol_enc);

//! get a list of atom names and their associated atedrg atom types
//!
//! @return a list of atom names and their associated atedrg atom types, return an empty list
//! on failure (atoms types are not in the dictionary or atom failure to look up the compound id)l
std::vector<std::pair<std::string, std::string> > get_acedrg_atom_types(const std::string &compound_id, int imol_enc) const;

//! write a PNG for the given compound_id. imol can be IMOL_ENC_ANY
//!
//! Currently this function does nothing (drawing is done with the not-allowed cairo)
Expand Down
27 changes: 25 additions & 2 deletions api/test-molecules-container.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5901,7 +5901,8 @@ int test_tricky_ligand_problem(molecules_container_t &mc) {
int imol_map = mc.read_mtz(reference_data("moorhen-tutorial-map-number-1.mtz"), "FWT", "PHWT", "W", false, false);

mc.set_imol_refinement_map(imol_map);
mc.import_cif_dictionary(reference_data("./nitrobenzene.cif"), imol);
mc.import_cif_dictionary(reference_data("YXG-as-LIG.cif"), imol);
mc.import_cif_dictionary(reference_data("nitrobenzene.cif"), imol);
std::cout << "------------- nitrobenzene.cif had been read --------------" << std::endl;
mc.refine_residues_using_atom_cid(imol, "//A/301", "SPHERE", 1000);
mc.write_coordinates(imol, "nitrobenzene-refined.pdb");
Expand All @@ -5912,6 +5913,27 @@ int test_tricky_ligand_problem(molecules_container_t &mc) {
return status;
}

int test_dictionary_acedrg_atom_types(molecules_container_t &mc) {

starting_test(__FUNCTION__);
int status = 0;

mc.import_cif_dictionary("YXG-as-LIG.cif", coot::protein_geometry::IMOL_ENC_ANY);
std::vector<std::pair<std::string, std::string> > v = mc.get_acedrg_atom_types("LIG", coot::protein_geometry::IMOL_ENC_ANY);

if (v.size() > 10) {
std::cout << "types vector size: " << v.size() << std::endl;
for (unsigned int i=0; i<v.size(); i++) {
if (v[i].first == "C21")
if (v[i].second == "C[6a](C[6a]C[6a]N[5a])(C[6a]C[6a]N[6a])(C[6a]C[6a]H){1|Cl<1>,1|N<2>,2|H<1>,4|C<3>}")
status = 1;
// std::cout << v[i].first << " " << v[i].second << std::endl;
}
}
return status;
}



int test_template(molecules_container_t &mc) {

Expand Down Expand Up @@ -6223,7 +6245,8 @@ int main(int argc, char **argv) {
// status += run_test(test_dictionary_conformers, "Dictionary Conformers", mc);
// status += run_test(test_ligand_distortion, "Ligand Distortion", mc);
// status += run_test(test_import_LIG_dictionary, "Import LIG.cif", mc);
status += run_test(test_tricky_ligand_problem, "Tricky Ligand import/refine", mc);
// status += run_test(test_tricky_ligand_problem, "Tricky Ligand import/refine", mc);
status += run_test(test_dictionary_acedrg_atom_types, "Acedrg atom types", mc);

if (status == n_tests) all_tests_status = 0;

Expand Down
27 changes: 27 additions & 0 deletions geometry/cif-parse-mon-lib.cc
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,33 @@ coot::protein_geometry::mon_lib_add_atom(const std::string &comp_id,
}
}

void
coot::protein_geometry::mon_lib_add_acedrg_atom_type(const std::string &comp_id, int imol_enc,
const std::string &atom_id,
const std::string &acedrg_atom_type) {

bool found = false;
for (unsigned int i=0; i<dict_res_restraints.size(); i++) {
if (dict_res_restraints[i].first == imol_enc) {
auto &restraints = dict_res_restraints[i].second;
if (restraints.read_number == read_number) {
found = true;
for (unsigned int iat=0; iat<restraints.atom_info.size(); iat++) {
auto &atom = restraints.atom_info[iat];
if (atom.atom_id == atom_id) {
atom.acedrg_atom_type = acedrg_atom_type;
}
}
}
}
}
// this should never happen
if (! found) {
dictionary_residue_restraints_t rest(comp_id, read_number);
std::pair<int, dictionary_residue_restraints_t> p(imol_enc, rest);
dict_res_restraints.push_back(p);
}
}

void
coot::protein_geometry::mon_lib_add_tree(std::string comp_id,
Expand Down
38 changes: 37 additions & 1 deletion geometry/cif-parse.cc
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,8 @@ coot::protein_geometry::init_refmac_mon_lib(std::string ciffilename, int read_nu
if (cat_name == "_pdbx_chem_comp_description_generator")
pdbx_chem_comp_description_generator(mmCIFLoop, imol_enc);

if (cat_name == "_chem_comp_acedrg")
chem_comp_acedrg(mmCIFLoop, imol_enc);
}
}
if (n_chiral) {
Expand Down Expand Up @@ -1894,7 +1896,41 @@ coot::protein_geometry::comp_plane(mmdb::mmcif::PLoop mmCIFLoop, int imol_enc) {
std::cout << "problem reading comp plane" << std::endl;
}
}
}
}

void
coot::protein_geometry::chem_comp_acedrg(mmdb::mmcif::PLoop mmCIFLoop, int imol_enc) {

std::string comp_id;
for (int j=0; j<mmCIFLoop->GetLoopLength(); j++) {
int ierr = 0;
int ierr_tot = 0;
std::string atom_id;
std::string atom_type;
char *s = mmCIFLoop->GetString("comp_id", j, ierr);
if (! ierr)
if (s)
comp_id = s;
ierr_tot += ierr;
s = mmCIFLoop->GetString("atom_id", j, ierr);
if (! ierr) {
atom_id = s;
}
ierr_tot += ierr;
s = mmCIFLoop->GetString("atom_type", j, ierr);
if (! ierr) {
atom_type = s;
}
ierr_tot += ierr;

if (ierr_tot == 0) {
mon_lib_add_acedrg_atom_type(comp_id, imol_enc, atom_id, atom_type);
}
}

}


//
int
coot::protein_geometry::add_chem_mods(mmdb::mmcif::PData data) {
Expand Down
23 changes: 23 additions & 0 deletions geometry/protein-geometry.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2764,3 +2764,26 @@ coot::protein_geometry::print_dictionary_store() const {
}

}


std::vector<std::pair<std::string, std::string> >
coot::protein_geometry::get_acedrg_atom_types(const std::string &comp_id,
int imol_enc) const {

std::vector<std::pair<std::string, std::string> > v;

std::pair<bool, dictionary_residue_restraints_t> r =
get_monomer_restraints_internal(comp_id, imol_enc, false);
if (r.first) {
const auto &restraints = r.second;
std::vector<dict_atom>::const_iterator it;
for (it=restraints.atom_info.begin(); it!=restraints.atom_info.end(); ++it) {
if (! it->acedrg_atom_type.empty()) {
auto pair = std::make_pair(it->atom_id, it->acedrg_atom_type);
v.push_back(pair);
}
}
}
return v;

}
9 changes: 9 additions & 0 deletions geometry/protein-geometry.hh
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,7 @@ namespace coot {
std::string atom_id_4c;
std::string type_symbol;
std::string type_energy;
std::string acedrg_atom_type;
aromaticity_t aromaticity;
bool is_hydrogen_flag;
std::pair<bool, float> partial_charge;
Expand Down Expand Up @@ -1374,6 +1375,8 @@ namespace coot {
// chirals added (almost certainly just
// one of them, of course).

void chem_comp_acedrg(mmdb::mmcif::PLoop mmCIFLoop, int imol_enc);

void add_chem_links (mmdb::mmcif::PLoop mmCIFLoop); // references to the modifications
// to the link groups (the modifications
// themselves are in data_mod_list)
Expand Down Expand Up @@ -1426,6 +1429,10 @@ namespace coot {
int imol_enc,
const dict_atom &atom_info);

void mon_lib_add_acedrg_atom_type(const std::string &comp_id, int imol_enc,
const std::string &atom_id,
const std::string &atom_type);

// called because they were all at origin, for example.
void delete_atom_positions(const std::string &comp_id, int imol_enc, int pos_type);

Expand Down Expand Up @@ -2247,6 +2254,8 @@ namespace coot {
void all_plane_restraints_to_improper_dihedrals();
void delete_plane_restraints();

std::vector<std::pair<std::string, std::string> > get_acedrg_atom_types(const std::string &comp_id,
int imol_enc) const;

#ifdef HAVE_CCP4SRS
match_results_t residue_from_best_match(mmdb::math::Graph &graph1, mmdb::math::Graph &graph2,
Expand Down

0 comments on commit 643a206

Please sign in to comment.