File: test_forcefield.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 (159 lines) | stat: -rw-r--r-- 6,142 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
156
157
158
159
// 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/forcefield_lookup.hh>
#include <promod3/core/message.hh>
#define BOOST_TEST_DYN_LINK
#include <boost/test/unit_test.hpp>

#include <promod3/loop/hydrogen_constructor.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;
}

void CheckIndexing(const ForcefieldLookup& ff_lookup, ForcefieldAminoAcid ff_aa,
                   bool is_nter, const HydrogenStorage& hydrogens) {
  // get AA stuff
  ost::conop::AminoAcid aa = ff_lookup.GetAA(ff_aa);
  const AminoAcidLookup& aa_lookup = AminoAcidLookup::GetInstance();
  // cook up bitset to hold all expected indices
  uint num_atoms = ff_lookup.GetNumAtoms(ff_aa, is_nter, false);
  std::vector<bool> idx_set(num_atoms, false);
  for (uint i = 0; i < aa_lookup.GetNumAtoms(aa); ++i) {
    uint my_idx = ff_lookup.GetHeavyIndex(ff_aa, i);
    BOOST_CHECK(my_idx < num_atoms);
    BOOST_CHECK(!idx_set[my_idx]);
    idx_set[my_idx] = true;
  }
  for (uint i = 0; i < aa_lookup.GetNumHydrogens(aa); ++i) {
    if (hydrogens.IsSet(i)) {
      uint my_idx = ff_lookup.GetHydrogenIndex(ff_aa, i);
      BOOST_CHECK(my_idx < num_atoms);
      BOOST_CHECK(!idx_set[my_idx]);
      idx_set[my_idx] = true;
    }
  }
  for (uint i = 0; i < num_atoms; ++i) {
    BOOST_CHECK(idx_set[i]);
  }
  // check C-TER OXT
  BOOST_CHECK_EQUAL(ff_lookup.GetNumAtoms(ff_aa, is_nter, true), num_atoms+1);
  // given that the rest is taken it must be last...
  BOOST_CHECK_EQUAL(ff_lookup.GetOXTIndex(ff_aa, is_nter), num_atoms);
}

void CheckIndexingAll(const ForcefieldLookup& ff_lookup,
                      const AllAtomPositions& all_pos, uint res_idx,
                      HydrogenStorage& hydrogens, ForcefieldAminoAcid ff_aa) {
  // check prot. state
  HisProtonationState his_prot_state;
  his_prot_state = (ff_aa == FF_HISD) ? PROT_STATE_HISD : PROT_STATE_HISE;
  // NON-N-TER
  ConstructHydrogens(all_pos, res_idx, hydrogens, false, his_prot_state);
  ConstructHydrogenN(all_pos, res_idx, -1.0472, hydrogens);
  if (ff_aa == FF_CYS2) hydrogens.ClearPos(CYS_HG_INDEX); // CYS2 -> remove HG
  CheckIndexing(ff_lookup, ff_aa, false, hydrogens);
  // N-TER
  ConstructHydrogens(all_pos, res_idx, hydrogens, false, his_prot_state);
  ConstructHydrogenNTerminal(all_pos, res_idx, hydrogens);
  if (ff_aa == FF_CYS2) hydrogens.ClearPos(CYS_HG_INDEX); // CYS2 -> remove HG
  CheckIndexing(ff_lookup, ff_aa, true, hydrogens);
}


} // anon ns

BOOST_AUTO_TEST_CASE(test_forcefield_amino_acid) {
  // first 20 AA must match conop::AminoAcid
  BOOST_CHECK_EQUAL(uint(FF_ALA), uint(ost::conop::ALA));
  BOOST_CHECK_EQUAL(uint(FF_ARG), uint(ost::conop::ARG));
  BOOST_CHECK_EQUAL(uint(FF_ASN), uint(ost::conop::ASN));
  BOOST_CHECK_EQUAL(uint(FF_ASP), uint(ost::conop::ASP));
  BOOST_CHECK_EQUAL(uint(FF_GLN), uint(ost::conop::GLN));
  BOOST_CHECK_EQUAL(uint(FF_GLU), uint(ost::conop::GLU));
  BOOST_CHECK_EQUAL(uint(FF_LYS), uint(ost::conop::LYS));
  BOOST_CHECK_EQUAL(uint(FF_SER), uint(ost::conop::SER));
  BOOST_CHECK_EQUAL(uint(FF_CYS), uint(ost::conop::CYS));
  BOOST_CHECK_EQUAL(uint(FF_MET), uint(ost::conop::MET));
  BOOST_CHECK_EQUAL(uint(FF_TRP), uint(ost::conop::TRP));
  BOOST_CHECK_EQUAL(uint(FF_TYR), uint(ost::conop::TYR));
  BOOST_CHECK_EQUAL(uint(FF_THR), uint(ost::conop::THR));
  BOOST_CHECK_EQUAL(uint(FF_VAL), uint(ost::conop::VAL));
  BOOST_CHECK_EQUAL(uint(FF_ILE), uint(ost::conop::ILE));
  BOOST_CHECK_EQUAL(uint(FF_LEU), uint(ost::conop::LEU));
  BOOST_CHECK_EQUAL(uint(FF_GLY), uint(ost::conop::GLY));
  BOOST_CHECK_EQUAL(uint(FF_PRO), uint(ost::conop::PRO));
  BOOST_CHECK_EQUAL(uint(FF_HISE), uint(ost::conop::HIS));
  BOOST_CHECK_EQUAL(uint(FF_PHE), uint(ost::conop::PHE));
}

BOOST_AUTO_TEST_CASE(test_forcefield_lookup_getaa) {
  // get lookup
  ForcefieldLookup ff_lookup;
  // check all ForcefieldAminoAcid
  for (uint i = 0; i <= FF_XXX; ++i) {
    ForcefieldAminoAcid ff_aa = ForcefieldAminoAcid(i);
    ost::conop::AminoAcid aa = ff_lookup.GetAA(ff_aa);
    if (i < ost::conop::XXX) {
      BOOST_CHECK_EQUAL(aa, ost::conop::AminoAcid(i));
    } else if (i < FF_XXX) {
      BOOST_CHECK(aa < ost::conop::XXX);
    } else {
      BOOST_CHECK_EQUAL(aa, ost::conop::XXX);
    }
  }
}

BOOST_AUTO_TEST_CASE(test_forcefield_lookup_indexing) {
  // get data
  ost::mol::EntityHandle test_ent = LoadTestStructure("data/all_aa.pdb");
  AllAtomPositions all_pos(test_ent.GetResidueList());
  HydrogenStorage hydrogens;
  // get lookups
  ForcefieldLookup ff_lookup;
  // check all residues
  for (uint res_idx = 0; res_idx < all_pos.GetNumResidues(); ++res_idx) {
    ost::conop::AminoAcid aa = all_pos.GetAA(res_idx);
    ForcefieldAminoAcid ff_aa = ForcefieldAminoAcid(aa);
    CheckIndexingAll(ff_lookup, all_pos, res_idx, hydrogens, ff_aa);
    // check modified AA
    if (aa == ost::conop::CYS) {
      CheckIndexingAll(ff_lookup, all_pos, res_idx, hydrogens, FF_CYS2);
    } else if (aa == ost::conop::HIS) {
      CheckIndexingAll(ff_lookup, all_pos, res_idx, hydrogens, FF_HISD);
    }
  }
}

BOOST_AUTO_TEST_SUITE_END();