Reduce changes in libdssp

This commit is contained in:
Maarten L. Hekkelman
2025-05-14 11:41:47 +02:00
parent 5218294347
commit 127502d384
4 changed files with 45 additions and 38 deletions

View File

@@ -68,12 +68,6 @@ class dssp
Middle
};
enum class ladder_direction_type
{
parallel,
antiparallel
};
static constexpr size_t kHistogramSize = 30;
struct statistics
@@ -156,7 +150,7 @@ class dssp
std::size_t nr_of_chis() const;
float chi(std::size_t index) const;
std::vector<float> chi() const
std::vector<float> chis() const
{
std::vector<float> result;
for (size_t i = 0; i < nr_of_chis(); ++i)
@@ -184,7 +178,7 @@ class dssp
double accessibility() const;
/// \brief returns resinfo, ladder and parallel
std::tuple<residue_info, int, ladder_direction_type> bridge_partner(int i) const;
std::tuple<residue_info, int, bool> bridge_partner(int i) const;
int sheet() const;
int strand() const;

View File

@@ -98,12 +98,12 @@ std::string ResidueToDSSPLine(const dssp::residue_info &info)
char bridgelabel[2] = { ' ', ' ' };
for (uint32_t i : { 0, 1 })
{
const auto &[p, ladder, direction] = info.bridge_partner(i);
const auto &[p, ladder, parallel] = info.bridge_partner(i);
if (not p)
continue;
bp[i] = p.nr() % 10000; // won't fit otherwise...
bridgelabel[i] = (direction == dssp::ladder_direction_type::parallel ? 'a' : 'A') + ladder % 26;
bridgelabel[i] = (parallel ? 'a' : 'A') + ladder % 26;
}
char sheet = ' ';
@@ -402,10 +402,10 @@ void writeLadders(cif::datablock &db, const dssp &dssp)
// Write out the DSSP ladders
struct ladder_info
{
ladder_info(int label, int sheet, dssp::ladder_direction_type direction, const dssp::residue_info &a, const dssp::residue_info &b)
ladder_info(int label, int sheet, bool parallel, const dssp::residue_info &a, const dssp::residue_info &b)
: ladder(label)
, sheet(sheet)
, direction(direction)
, parallel(parallel)
, pairs({ { a, b } })
{
}
@@ -417,7 +417,7 @@ void writeLadders(cif::datablock &db, const dssp &dssp)
int ladder;
int sheet;
dssp::ladder_direction_type direction;
bool parallel;
std::vector<std::pair<dssp::residue_info, dssp::residue_info>> pairs;
};
@@ -427,7 +427,7 @@ void writeLadders(cif::datablock &db, const dssp &dssp)
{
for (int i : { 0, 1 })
{
const auto &[p, ladder, direction] = res.bridge_partner(i);
const auto &[p, ladder, parallel] = res.bridge_partner(i);
if (not p)
continue;
@@ -438,7 +438,7 @@ void writeLadders(cif::datablock &db, const dssp &dssp)
if (l.ladder != ladder)
continue;
assert(l.direction == direction);
assert(l.parallel == parallel);
if (find_if(l.pairs.begin(), l.pairs.end(), [na = p.nr(), nb = res.nr()](const auto &p)
{ return p.first.nr() == na and p.second.nr() == nb; }) != l.pairs.end())
@@ -455,7 +455,7 @@ void writeLadders(cif::datablock &db, const dssp &dssp)
if (not is_new)
continue;
ladders.emplace_back(ladder, res.sheet() - 1, direction, res, p);
ladders.emplace_back(ladder, res.sheet() - 1, parallel, res, p);
}
}
@@ -472,7 +472,7 @@ void writeLadders(cif::datablock &db, const dssp &dssp)
{ "sheet_id", cif::cif_id_for_number(l.sheet) },
{ "range_id_1", cif::cif_id_for_number(beg1.strand() - 1) },
{ "range_id_2", cif::cif_id_for_number(beg2.strand() - 1) },
{ "type", l.direction == dssp::ladder_direction_type::parallel ? "parallel" : "anti-parallel" },
{ "type", l.parallel ? "parallel" : "anti-parallel" },
{ "beg_1_label_comp_id", beg1.compound_id() },
{ "beg_1_label_asym_id", beg1.asym_id() },

View File

@@ -2063,13 +2063,21 @@ const std::map<residue_type, std::vector<std::string>> kChiAtomsMap = {
{ MapResidue("VAL"), { "CG1" } }
};
std::vector<float> dssp::residue_info::chi() const
std::size_t dssp::residue_info::nr_of_chis() const
{
std::vector<float> result;
auto i = kChiAtomsMap.find(m_impl->mType);
return i != kChiAtomsMap.end() ? i->second.size() : 0;
}
float dssp::residue_info::chi(std::size_t index) const
{
float result = 0;
auto type = m_impl->mType;
if (auto i = kChiAtomsMap.find(type); i != kChiAtomsMap.end())
auto i = kChiAtomsMap.find(type);
if (i != kChiAtomsMap.end() and index < i->second.size())
{
std::vector<std::string> atoms{ "N", "CA", "CB" };
@@ -2084,14 +2092,11 @@ std::vector<float> dssp::residue_info::chi() const
atoms.back() = "CG2";
}
for (size_t ix = 0; ix < i->second.size(); ++ix)
{
result.push_back(static_cast<float>(dihedral_angle(
m_impl->get_atom(atoms[ix + 0]),
m_impl->get_atom(atoms[ix + 1]),
m_impl->get_atom(atoms[ix + 2]),
m_impl->get_atom(atoms[ix + 3]))));
}
result = static_cast<float>(dihedral_angle(
m_impl->get_atom(atoms[index + 0]),
m_impl->get_atom(atoms[index + 1]),
m_impl->get_atom(atoms[index + 2]),
m_impl->get_atom(atoms[index + 3])));
}
return result;
@@ -2147,13 +2152,13 @@ double dssp::residue_info::accessibility() const
return m_impl->mAccessibility;
}
std::tuple<dssp::residue_info, int, dssp::ladder_direction_type> dssp::residue_info::bridge_partner(int i) const
std::tuple<dssp::residue_info, int, bool> dssp::residue_info::bridge_partner(int i) const
{
auto bp = m_impl->GetBetaPartner(i);
residue_info ri(bp.m_residue);
return std::make_tuple(std::move(ri), bp.ladder, bp.parallel ? ladder_direction_type::parallel : ladder_direction_type::antiparallel);
return std::make_tuple(std::move(ri), bp.ladder, bp.parallel);
}
int dssp::residue_info::sheet() const

View File

@@ -16,6 +16,12 @@ struct statistics_wrapper
dssp::statistics m_stats;
};
enum class ladder_direction_type
{
parallel,
antiparallel
};
struct residue_info_wrapper
{
};
@@ -193,19 +199,21 @@ struct to_python_partner
struct to_python_bridge_partner
{
static PyObject *convert(const std::tuple<dssp::residue_info, int, dssp::ladder_direction_type> &v)
static PyObject *convert(const std::tuple<dssp::residue_info, int, bool> &v)
{
if (auto &[ri, nr, direction] = v; ri)
if (auto &[ri, nr, parallel] = v; ri)
{
boost::python::type_info iv = boost::python::type_id<dssp::residue_info>();
const boost::python::converter::registration* cv = boost::python::converter::registry::query(iv);
assert(cv != nullptr);
boost::python::type_info dv = boost::python::type_id<dssp::ladder_direction_type>();
boost::python::type_info dv = boost::python::type_id<ladder_direction_type>();
const boost::python::converter::registration* ev = boost::python::converter::registry::query(dv);
assert(ev != nullptr);
auto c = cv->to_python(&ri);
ladder_direction_type direction = parallel ? ladder_direction_type::parallel : ladder_direction_type::antiparallel;
auto e = ev->to_python(&direction);
return boost::python::incref(boost::python::make_tuple(
@@ -235,7 +243,7 @@ BOOST_PYTHON_MODULE(mkdssp)
to_python_converter<std::vector<float>, to_python_list_of_floats>();
to_python_converter<std::tuple<float, float, float>, to_python_point>();
to_python_converter<std::tuple<dssp::residue_info, double>, to_python_partner>();
to_python_converter<std::tuple<dssp::residue_info, int, dssp::ladder_direction_type>, to_python_bridge_partner>();
to_python_converter<std::tuple<dssp::residue_info, int, bool>, to_python_bridge_partner>();
enum_<dssp::structure_type>("structure_type")
.value("Loop", dssp::structure_type::Loop)
@@ -261,9 +269,9 @@ BOOST_PYTHON_MODULE(mkdssp)
.value("StartAndEnd", dssp::helix_position_type::StartAndEnd)
.value("Middle", dssp::helix_position_type::Middle);
enum_<dssp::ladder_direction_type>("ladder_direction_type")
.value("parallel", dssp::ladder_direction_type::parallel)
.value("anti_parallel", dssp::ladder_direction_type::antiparallel);
enum_<ladder_direction_type>("ladder_direction_type")
.value("parallel", ladder_direction_type::parallel)
.value("anti_parallel", ladder_direction_type::antiparallel);
enum_<dssp::chain_break_type>("chain_break_type")
.value("None", dssp::chain_break_type::None)
@@ -299,7 +307,7 @@ BOOST_PYTHON_MODULE(mkdssp)
.add_property("is_pre_pro", &dssp::residue_info::is_pre_pro)
.add_property("is_cis", &dssp::residue_info::is_cis)
.add_property("chiral_volume", &dssp::residue_info::chiral_volume)
.add_property("chi", &dssp::residue_info::chi)
.add_property("chi", &dssp::residue_info::chis)
.add_property("ca_location", &dssp::residue_info::ca_location)
.add_property("chain_break", &dssp::residue_info::chain_break)
.add_property("nr", &dssp::residue_info::nr)