File: test_hydrogens.cc

package info (click to toggle)
promod3 3.4.2%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 966,596 kB
  • sloc: cpp: 55,820; python: 18,058; makefile: 85; sh: 51
file content (155 lines) | stat: -rw-r--r-- 5,772 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
// Copyright (c) 2013-2020, SIB - Swiss Institute of Bioinformatics and
//                          Biozentrum - University of Basel
// 
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// 
//   http://www.apache.org/licenses/LICENSE-2.0
// 
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.



#include <promod3/loop/hydrogen_rule_lookup.hh>
#include <promod3/loop/hydrogen_constructor.hh>
#include <promod3/core/message.hh>
#define BOOST_TEST_DYN_LINK
#include <boost/test/unit_test.hpp>

#include <ost/mol/atom_view.hh>
#include <ost/mol/entity_view.hh>
#include <ost/mol/bond_handle.hh>
#include <ost/io/mol/pdb_reader.hh>
#include <ost/conop/heuristic.hh>

BOOST_AUTO_TEST_SUITE( loop );

using namespace promod3::loop;

namespace {

ost::mol::EntityHandle LoadTestStructure(const String& pdb_name) {
  ost::io::PDBReader reader(pdb_name, ost::io::IOProfile());
  ost::mol::EntityHandle test_ent = ost::mol::CreateEntity();
  reader.Import(test_ent);
  ost::conop::HeuristicProcessor heu_proc;
  heu_proc.Process(test_ent);

  return test_ent;
}

// get atom-atom RMSD and check that all atoms exist in both
Real GetCheckRMSD(const ost::mol::EntityHandle& ent, const String& ref_path) {
  // get ref
  ost::mol::EntityHandle ent2 = LoadTestStructure(ref_path);
  // compare atom by atom
  Real sum = 0;
  ost::mol::ResidueHandleList res_list = ent.GetResidueList();
  ost::mol::ResidueHandleList res_list2 = ent2.GetResidueList();
  BOOST_CHECK_EQUAL(ent.GetResidueCount(), ent2.GetResidueCount());
  for (int i_r = 0; i_r < ent.GetResidueCount(); ++i_r) {
    const ost::mol::ResidueHandle& res = res_list[i_r];
    const ost::mol::ResidueHandle& res2 = res_list2[i_r];
    ost::mol::AtomHandleList atoms = res.GetAtomList();
    BOOST_CHECK_EQUAL(res.GetAtomCount(), res2.GetAtomCount());
    for (int i_a = 0; i_a < res.GetAtomCount(); ++i_a) {
      ost::mol::AtomHandle atom2 = res2.FindAtom(atoms[i_a].GetName());
      BOOST_CHECK(atom2.IsValid());
      sum += geom::Length2(atoms[i_a].GetPos() - atom2.GetPos());
    }
  }
  return std::sqrt(sum / ent.GetAtomCount());
}

ost::mol::ResidueView GetHIS(ost::mol::EntityHandle& ent) {
  ost::mol::EntityView ev_his = ent.Select("rname=HIS");
  ost::mol::ResidueViewList rvl_his = ev_his.GetResidueList();
  BOOST_CHECK_EQUAL(rvl_his.size(), size_t(1));
  return rvl_his[0];
}

template <typename T>
void CheckProtonations(const T& prot) {
  ost::mol::EntityHandle new_ent;
  Real rmsd;
  // check default
  new_ent = ConstructProtonatedEntity(prot);
  rmsd = GetCheckRMSD(new_ent, "data/all_aa_prot_ref.pdb");
  BOOST_CHECK(rmsd < 0.01);
  // check prot. states -> should add/replace HD1/HE2 of HIS
  ost::mol::ResidueView rv_his = GetHIS(new_ent);
  BOOST_CHECK(!rv_his.FindAtom("HD1").IsValid());
  BOOST_CHECK(rv_his.FindAtom("HE2").IsValid());
  int ref_count = new_ent.GetAtomCount();
  new_ent = ConstructProtonatedEntity(prot, false, PROT_STATE_HISD);
  BOOST_CHECK_EQUAL(new_ent.GetAtomCount(), ref_count);
  rv_his = GetHIS(new_ent);
  BOOST_CHECK(rv_his.FindAtom("HD1").IsValid());
  BOOST_CHECK(!rv_his.FindAtom("HE2").IsValid());
  new_ent = ConstructProtonatedEntity(prot, false, PROT_STATE_HISH);
  BOOST_CHECK_EQUAL(new_ent.GetAtomCount(), ref_count+1);
  rv_his = GetHIS(new_ent);
  BOOST_CHECK(rv_his.FindAtom("HD1").IsValid());
  BOOST_CHECK(rv_his.FindAtom("HE2").IsValid());
  // check some combinations
  new_ent = ConstructProtonatedEntity(prot, true);
  rmsd = GetCheckRMSD(new_ent, "data/all_aa_prot_polar_hise.pdb");
  BOOST_CHECK(rmsd < 0.01);
  new_ent = ConstructProtonatedEntity(prot, true, PROT_STATE_HISH);
  rmsd = GetCheckRMSD(new_ent, "data/all_aa_prot_polar_hish.pdb");
  BOOST_CHECK(rmsd < 0.01);
  new_ent = ConstructProtonatedEntity(prot, true, PROT_STATE_HISD);
  rmsd = GetCheckRMSD(new_ent, "data/all_aa_prot_polar_hisd.pdb");
  BOOST_CHECK(rmsd < 0.01);
}

} // anon ns

BOOST_AUTO_TEST_CASE(test_construct_hydrogens_ost_ent) {
  // get data
  ost::mol::EntityHandle test_ent = LoadTestStructure("data/all_aa.pdb");
  // check protonations
  CheckProtonations(test_ent);
}

BOOST_AUTO_TEST_CASE(test_construct_hydrogens_aap) {
  // get data
  ost::mol::EntityHandle test_ent = LoadTestStructure("data/all_aa.pdb");
  AllAtomPositions all_pos(test_ent.GetResidueList());
  // check protonations
  CheckProtonations(all_pos);
}

BOOST_AUTO_TEST_CASE(test_hydrogen_single_rules) {
  // check if all single rules are defined as expected
  const AminoAcidLookup& aa_lookup = AminoAcidLookup::GetInstance();
  const HydrogenRuleLookup& hy_lookup = HydrogenRuleLookup::GetInstance();
  for (uint i = 0; i <= XXX_NUM_HYDROGENS; ++i) {
    const AminoAcidHydrogen aah = AminoAcidHydrogen(i);
    const HydrogenRule* p_rule = hy_lookup.GetRule(aah);
    if (aa_lookup.GetAnchorAtomIndex(aah) == BB_N_INDEX) {
      BOOST_CHECK(p_rule == NULL);
    } else if (aah == XXX_NUM_HYDROGENS) {
      BOOST_CHECK(p_rule == NULL);
    } else {
      BOOST_CHECK(p_rule != NULL);
      // check that we actually construct this hydrogen with it
      const ost::conop::AminoAcid aa = aa_lookup.GetAA(aah);
      bool found_it = false;
      for (uint j = 0; j < p_rule->num_hydrogens; ++j) {
        if (aah == aa_lookup.GetAAH(aa, p_rule->hydro_idx[j])) {
          found_it = true;
          break;
        }
      }
      BOOST_CHECK(found_it);
    }
  }
}

BOOST_AUTO_TEST_SUITE_END();