Skip to content

Commit 773a97c

Browse files
committed
pdb: fix determining of _struct_conn.conn_type_id (#357)
in some cases covalent bonds were falsely regarded as metal coordination
1 parent 8da9362 commit 773a97c

File tree

1 file changed

+21
-9
lines changed

1 file changed

+21
-9
lines changed

src/pdb.cpp

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,10 @@ El infer_element_from_padded_name(const char* name) {
136136
return find_element(name);
137137
}
138138

139+
bool element_from_padded_name_is_ambiguous(const char* name) {
140+
return name[0] != ' ' && name[3] != ' ' && !is_digit(name[0]) && !is_digit(name[1]);
141+
}
142+
139143
// "28-MAR-07" -> "2007-03-28"
140144
// (we also accept less standard format "28-Mar-2007" as used by BUSTER)
141145
// We do not check if the date is correct.
@@ -694,15 +698,6 @@ void process_conn(Structure& st, const std::vector<std::string>& conn_records) {
694698
if (record.length() < 57)
695699
continue;
696700
Connection c;
697-
// emulating names used in wwPDB mmCIFs (covaleN and metalcN)
698-
if (is_metal(find_element(&record[12])) ||
699-
is_metal(find_element(&record[42]))) {
700-
c.name = "metalc" + std::to_string(++metalc_count);
701-
c.type = Connection::MetalC;
702-
} else {
703-
c.name = "covale" + std::to_string(++covale_count);
704-
c.type = Connection::Covale;
705-
}
706701
for (int i : {0, 1}) {
707702
const char* t = record.c_str() + 30 * i;
708703
AtomAddress& ad = (i == 0 ? c.partner1 : c.partner2);
@@ -711,6 +706,23 @@ void process_conn(Structure& st, const std::vector<std::string>& conn_records) {
711706
ad.atom_name = read_string(t + 12, 4);
712707
ad.altloc = read_altloc(t[16]);
713708
}
709+
auto get_elem = [&](const char* name, const AtomAddress& ad) {
710+
if (element_from_padded_name_is_ambiguous(name)) {
711+
const_CRA cra = st.first_model().find_cra(ad);
712+
if (cra.atom)
713+
return cra.atom->element.elem;
714+
}
715+
return infer_element_from_padded_name(name);
716+
};
717+
// emulating names used in wwPDB mmCIFs (covaleN and metalcN)
718+
if (is_metal(get_elem(&record[12], c.partner1)) ||
719+
is_metal(get_elem(&record[42], c.partner2))) {
720+
c.name = "metalc" + std::to_string(++metalc_count);
721+
c.type = Connection::MetalC;
722+
} else {
723+
c.name = "covale" + std::to_string(++covale_count);
724+
c.type = Connection::Covale;
725+
}
714726
c.asu = compare_link_symops(record, c.reported_sym);
715727
if (record.length() > 73) {
716728
if (record[4] == 'R')

0 commit comments

Comments
 (0)