Skip to content

Commit

Permalink
PDBSelector now works with PDBRecord, not raw line
Browse files Browse the repository at this point in the history
Rather than passing a raw line of text from the PDB
file to PDBSelector, pass a PDBRecord type. This wraps
either the PDB text or the equivalent parsed data
from the atom_site table in an mmCIF file, and provides
methods to get atom/residue name, etc. This ensures
that when working with mmCIF we are not restricted
to PDB format limitations, such as single-character
chain IDs or insertion codes. Closes #1083.
  • Loading branch information
benmwebb committed Sep 28, 2023
1 parent 5dc6320 commit 584c028
Show file tree
Hide file tree
Showing 6 changed files with 301 additions and 153 deletions.
39 changes: 38 additions & 1 deletion modules/atom/include/internal/pdb.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* \file internal/pdb.h
* \brief A class with static functions for parsing PDB files
*
* Copyright 2007-2022 IMP Inventors. All rights reserved.
* Copyright 2007-2023 IMP Inventors. All rights reserved.
*
*/

Expand All @@ -14,6 +14,7 @@
#include <IMP/atom/Hierarchy.h>

#include <IMP/base_types.h>
#include "ihm_format.h"

#include <vector>

Expand Down Expand Up @@ -111,6 +112,42 @@ IMPATOMEXPORT String atom_element(const String& pdb_line);
IMPATOMEXPORT Vector<unsigned short> connected_atoms(
const String& pdb_line);

//! Handle a keyword in an mmCIF file
class CifKeyword {
struct ihm_keyword *k_;
public:
CifKeyword(struct ihm_category *c, std::string name)
: k_(ihm_keyword_new(c, name.c_str())) {}

//! Get raw string value of the keyword (may be null)
const char *data() { return k_->data; }

//! Get value as a string, or the empty string if it is missing
const char *as_str() {
if (k_->omitted || k_->unknown || !k_->in_file) {
return "";
} else {
return k_->data;
}
}

float as_float(float default_value=0.) {
if (k_->omitted || k_->unknown || !k_->in_file) {
return default_value;
} else {
return boost::lexical_cast<float>(k_->data);
}
}

int as_int(int default_value=0) {
if (k_->omitted || k_->unknown || !k_->in_file) {
return default_value;
} else {
return boost::lexical_cast<int>(k_->data);
}
}
};

//! write particles as ATOMs to PDB (assumes Particles are valid Atoms)
IMPATOMEXPORT void write_pdb(const ParticlesTemp& ps,
TextOutput out);
Expand Down
Loading

0 comments on commit 584c028

Please sign in to comment.