| 1 |
|
|---|
| 2 | #include "dihedral.h"
|
|---|
| 3 |
|
|---|
| 4 | Dihedral::Dihedral(Atom* a1, Atom* a2, Atom* a3, Atom* a4)
|
|---|
| 5 | {
|
|---|
| 6 | if (a1==a2||a1==a3||a1==a4||a2==a3||a2==a4||a3==a4)
|
|---|
| 7 | throw std::invalid_argument(err_msg_dup_atom());
|
|---|
| 8 | _atoms[0] = a1;
|
|---|
| 9 | _atoms[1] = a2;
|
|---|
| 10 | _atoms[2] = a3;
|
|---|
| 11 | _atoms[3] = a4;
|
|---|
| 12 |
|
|---|
| 13 | Structure* as = atoms()[0]->structure();
|
|---|
| 14 | for (int i=1; i<4; ++i) {
|
|---|
| 15 | if (atoms()[i]->structure() != as)
|
|---|
| 16 | throw std::invalid_argument(err_msg_multi_struct());
|
|---|
| 17 | }
|
|---|
| 18 | }
|
|---|
| 19 |
|
|---|
| 20 | Real Dihedral::angle() const
|
|---|
| 21 | {
|
|---|
| 22 | return geometry::dihedral_angle<Coord, Real>(atoms()[0]->coord(),
|
|---|
| 23 | atoms()[1]->coord(), atoms()[2]->coord(), atoms()[3]->coord());
|
|---|
| 24 | }
|
|---|
| 25 |
|
|---|
| 26 | Residue* Dihedral::residue() const
|
|---|
| 27 | {
|
|---|
| 28 | if (_residue == nullptr)
|
|---|
| 29 | throw std::runtime_error(err_msg_no_residue());
|
|---|
| 30 | return _residue;
|
|---|
| 31 | }
|
|---|
| 32 |
|
|---|
| 33 |
|
|---|
| 34 |
|
|---|
| 35 | Proper_Dihedral::Proper_Dihedral(Atom* a1, Atom* a2, Atom* a3, Atom* a4)
|
|---|
| 36 | : Dihedral(a1, a2, a3, a4)
|
|---|
| 37 | {
|
|---|
| 38 | Atom* ba1 = atoms()[0];
|
|---|
| 39 | bool found_bond;
|
|---|
| 40 | for (int i=1; i<4; ++i) {
|
|---|
| 41 | found_bond = false;
|
|---|
| 42 | Atom* ba2 = atoms()[i];
|
|---|
| 43 | for (auto bond: ba1->bonds()) {
|
|---|
| 44 | if (bond->atoms()[0] == ba2 || bond->atoms()[1] == ba2) {
|
|---|
| 45 | _bonds[i-1] = bond;
|
|---|
| 46 | found_bond = true;
|
|---|
| 47 | break;
|
|---|
| 48 | }
|
|---|
| 49 | }
|
|---|
| 50 | if (!found_bond) {
|
|---|
| 51 | throw std::invalid_argument(err_msg_not_bonded());
|
|---|
| 52 | }
|
|---|
| 53 | ba1 = ba2;
|
|---|
| 54 | }
|
|---|
| 55 | }
|
|---|