Gemmi C++ API
Loading...
Searching...
No Matches
riding_h.hpp
Go to the documentation of this file.
1// Copyright 2018-2022 Global Phasing Ltd.
2//
3// Place hydrogens according to bond lengths and angles from monomer library.
4
5#ifndef GEMMI_RIDING_H_HPP_
6#define GEMMI_RIDING_H_HPP_
7
8#include <cmath> // for isnan
9#include "topo.hpp" // for Topo
10
11namespace gemmi {
12
14
16 double default_scale=1.) {
17 for (const Topo::Bond& t : topo.bonds) {
18 assert(t.atoms[0] != nullptr && t.atoms[1] != nullptr);
19 if (t.atoms[0]->is_hydrogen() || t.atoms[1]->is_hydrogen()) {
20 Position u = t.atoms[1]->pos - t.atoms[0]->pos;
21 double scale = t.restr->distance(of) / u.length();
22 if (std::isnan(scale))
23 scale = default_scale;
24 if (t.atoms[1]->is_hydrogen())
25 t.atoms[1]->pos = t.atoms[0]->pos + u * scale;
26 else
27 t.atoms[0]->pos = t.atoms[1]->pos - u * scale;
28 }
29 }
30}
31
32} // namespace gemmi
33#endif
#define GEMMI_DLL
Definition fail.hpp:53
void adjust_hydrogen_distances(Topo &topo, Restraints::DistanceOf of, double default_scale=1.)
Definition riding_h.hpp:15
GEMMI_DLL void place_hydrogens_on_all_atoms(Topo &topo)
Coordinates in Angstroms - orthogonal (Cartesian) coordinates.
Definition unitcell.hpp:32