12 #include <IMP/atom/atom_config.h>
16 #include "internal/pdb.h"
23 #include <IMP/internal/utility.h>
24 #include <IMP/internal/pdb.h>
25 #include <boost/format.hpp>
26 #include <boost/algorithm/string.hpp>
27 #include <cereal/access.hpp>
28 #include <cereal/types/base_class.hpp>
29 #include <cereal/types/polymorphic.hpp>
31 IMPATOM_BEGIN_NAMESPACE
35 const std::string *line_;
36 internal::CifKeyword *group_, *element_, *atom_name_, *alt_loc_id_,
37 *residue_name_, *auth_chain_, *chain_, *auth_seq_id_;
38 bool use_line_, use_keywords_;
40 PDBRecord() : use_line_(
false), use_keywords_(
false) {}
45 void set_line(
const std::string &line);
50 void set_keywords(internal::CifKeyword &group,
51 internal::CifKeyword &element,
52 internal::CifKeyword &atom_name,
53 internal::CifKeyword &alt_loc_id,
54 internal::CifKeyword &residue_name,
55 internal::CifKeyword &auth_chain,
56 internal::CifKeyword &chain,
57 internal::CifKeyword &auth_seq_id);
62 std::string get_alt_loc_indicator()
const;
65 bool get_is_atom()
const;
68 std::string get_trimmed_atom_name()
const;
73 std::string get_padded_atom_name()
const;
76 std::string get_residue_name()
const;
85 std::string get_element()
const;
107 virtual bool get_is_selected(
const PDBRecord &record)
const = 0;
122 return (alt_loc ==
" " || alt_loc ==
"" || alt_loc ==
"A");
135 return (NonAlternativePDBSelector::get_is_selected(record) &&
148 if (!NonAlternativePDBSelector::get_is_selected(record))
return false;
150 return (type[1] ==
'C' && type[2] ==
'A' && type[3] ==
' ');
162 if (!NonAlternativePDBSelector::get_is_selected(record))
return false;
164 return (type[1] ==
'C' && type[2] ==
'B' && type[3] ==
' ');
178 std::string name =
"AtomTypePDBSelector%1%")
180 std::sort(atom_types_.begin(), atom_types_.end());
185 return std::binary_search(atom_types_.begin(), atom_types_.end(), type);
199 std::string name =
"ResidueTypePDBSelector%1%")
200 :
PDBSelector(name), residue_types_(residue_types) {
201 std::sort(residue_types_.begin(), residue_types_.end());
206 return std::binary_search(residue_types_.begin(), residue_types_.end(),
219 if (!NonAlternativePDBSelector::get_is_selected(record))
return false;
221 return (type[1] ==
'C' && type[2] ==
' ' && type[3] ==
' ');
233 if (!NonAlternativePDBSelector::get_is_selected(record))
return false;
235 return (type[1] ==
'N' && type[2] ==
' ' && type[3] ==
' ');
259 if (!NonAlternativePDBSelector::get_is_selected(record)) {
263 return std::binary_search(chains_.begin(), chains_.end(), cid);
273 std::string name =
"ChainPDBSelector%1%")
275 std::sort(chains_.begin(), chains_.end());
282 IMPATOM_DEPRECATED_METHOD_DECL(2.20)
286 IMPATOM_DEPRECATED_METHOD_DEF(
287 2.20,
"Pass a list of chain ID strings instead");
288 for (
size_t i = 0; i < chains.length(); ++i) {
289 chains_.push_back(std::string(1, chains[i]));
291 std::sort(chains_.begin(), chains_.end());
306 if (!NonAlternativePDBSelector::get_is_selected(record)) {
310 return (res_name ==
"HOH" || res_name ==
"DOD");
317 bool is_hydrogen(
const PDBRecord &record)
const;
324 if (!NonAlternativePDBSelector::get_is_selected(record))
return false;
325 return is_hydrogen(record);
336 if (!NonAlternativePDBSelector::get_is_selected(record)) {
339 return (!ws_->get_is_selected(record) && !hs_->get_is_selected(record));
358 if (!NonAlternativePDBSelector::get_is_selected(record)) {
361 return (!hs_->get_is_selected(record));
378 if (!NonAlternativePDBSelector::get_is_selected(record)) {
381 return (!ws_->get_is_selected(record));
398 if (!NonWaterNonHydrogenPDBSelector::get_is_selected(record))
401 return ((type[1] ==
'N' && type[2] ==
' ' && type[3] ==
' ') ||
402 (type[1] ==
'C' && type[2] ==
'A' && type[3] ==
' ') ||
403 (type[1] ==
'C' && type[2] ==
' ' && type[3] ==
' ') ||
404 (type[1] ==
'O' && type[2] ==
' ' && type[3] ==
' '));
416 if (!NonAlternativePDBSelector::get_is_selected(record))
return false;
418 return (type[1] ==
'P' && type[2] ==
' ' && type[3] ==
' ');
439 return a_->get_is_selected(record) && b_->get_is_selected(record);
443 :
PDBSelector(
"AndPDBSelector%1%"), a_(a), b_(b) {}
462 return a_->get_is_selected(record) || b_->get_is_selected(record);
486 return a_->get_is_selected(record) != b_->get_is_selected(record);
490 :
PDBSelector(
"XorPDBSelector%1%"), a_(a), b_(b) {}
509 return !a_->get_is_selected(record);
559 inline PDBSelector *get_default_pdb_selector() {
560 return new NonWaterPDBSelector();
575 IMPATOMEXPORT Hierarchy
576 read_pdb(TextInput input, Model *model,
577 PDBSelector *selector = get_default_pdb_selector(),
578 bool select_first_model =
true
581 bool no_radii =
false
600 IMPATOMEXPORT
void read_pdb(TextInput input,
int model, Hierarchy h);
604 IMPATOMEXPORT Hierarchies
606 PDBSelector *selector = get_default_pdb_selector()
632 IMPATOMEXPORT
void write_pdb(
const Selection &mhd, TextOutput out,
633 unsigned int model = 1);
644 unsigned int model = 1);
657 IMPATOMEXPORT std::string get_pdb_string(
659 ResidueType rt = atom::ALA,
char chain =
' ',
int res_index = 1,
660 char res_icode =
' ',
double occupancy = 1.00,
double tempFactor = 0.00,
670 IMPATOMEXPORT std::string get_pdb_conect_record_string(
int,
int);
680 std::string filename_;
683 friend class cereal::access;
685 template<
class Archive>
void serialize(Archive &ar) {
686 ar(cereal::base_class<OptimizerState>(
this), filename_, pis_);
693 std::string filename);
698 virtual void do_update(
unsigned int call)
override;
703 IMPATOM_END_NAMESPACE
ChainPDBSelector(Strings chains, std::string name="ChainPDBSelector%1%")
Allow any of the named chains.
Select non water and non hydrogen atoms.
std::string get_chain_id() const
Returns the chain ID.
Define the elements used in IMP.
#define IMP_SHOWABLE_INLINE(Name, how_to_show)
Declare the methods needed by an object that can be printed.
Select all backbone (N,CA,C,O) ATOM records.
Represent a single ATOM/HETATM "line" in PDB or mmCIF format.
Select all non-water ATOM and HETATM records.
bool get_is_selected(const PDBRecord &record) const override
Return true if the line should be processed.
IMP::Vector< String > Strings
Standard way to pass a bunch of String values.
Select all P (= phosphate) ATOM records.
Select non hydrogen atoms.
Select atoms which are selected by both selectors.
std::string get_trimmed_atom_name() const
Returns the atom type as a string with no leading or trailing whitespace.
#define IMP_OBJECT_METHODS(Name)
Define the basic things needed by any Object.
Storage of a model, its restraints, constraints and particles.
Select all N ATOM records.
void write_pdb(const Selection &mhd, TextOutput out, unsigned int model=1)
Handling of file input/output.
virtual void do_update(unsigned int)
bool get_is_selected(const PDBRecord &) const override
Return true if the line should be processed.
std::string get_alt_loc_indicator() const
Returns the alternative location indicator.
Select all atoms in residues of the given types.
void read_pdb(TextInput input, int model, Hierarchy h)
A more IMP-like version of the std::vector.
Take Decorator, Particle or ParticleIndex.
Select all C (not CA or CB) ATOM records.
bool get_is_selected(const PDBRecord &record) const override
Return true if the line should be processed.
Class for storing model, its restraints, constraints, and particles.
void write_pdb_of_c_alphas(const Selection &mhd, TextOutput out, unsigned int model=1)
Write a hierarchy to a PDB as C_alpha atoms.
bool get_is_selected(const PDBRecord &record) const override
Return true if the line should be processed.
bool get_is_selected(const PDBRecord &record) const override
Return true if the line should be processed.
Decorator for helping deal with a hierarchy of molecules.
Base class for a simple primitive-like type.
Select all CB ATOM records.
Select all ATOM and HETATM records which are not alternatives.
#define IMP_VALUES(Name, PluralName)
Define the type for storing sets of values.
bool get_is_selected(const PDBRecord &record) const override
Return true if the line should be processed.
Select all non-alternative ATOM records.
bool get_is_selected(const PDBRecord &record) const override
Return true if the line should be processed.
Common base class for heavy weight IMP objects.
bool get_is_selected(const PDBRecord &record) const override
Return true if the line should be processed.
bool get_is_selected(const PDBRecord &record) const override
Return true if the line should be processed.
bool get_is_selected(const PDBRecord &record) const override
Return true if the line should be processed.
bool get_is_selected(const PDBRecord &record) const override
Return true if the line should be processed.
#define IMP_OBJECT_SERIALIZE_DECL(Name)
Declare methods needed for serialization of Object pointers.
A smart pointer to a ref-counted Object that is a class member.
bool get_is_selected(const PDBRecord &record) const override
Return true if the line should be processed.
bool get_is_atom() const
Returns true if the record is an ATOM record.
bool get_is_selected(const PDBRecord &record) const override
Return true if the line should be processed.
Select all atoms of the given types.
virtual ModelObjectsTemp do_get_inputs() const override
Classes to handle individual model particles. (Note that implementation of inline functions is in int...
bool get_is_selected(const PDBRecord &record) const override
Return true if the line should be processed.
bool get_is_selected(const PDBRecord &record) const override
Return true if the line should be processed.
#define IMP_OBJECTS(Name, PluralName)
Define the types for storing lists of object pointers.
Defines a selector that will pick every ATOM and HETATM record.
Macros for maintaining molecular hierarchies.
Select atoms which are not selected by a given selector.
Hierarchies read_multimodel_pdb(TextInput input, Model *model, PDBSelector *selector=get_default_pdb_selector())
std::string get_padded_atom_name() const
Returns the atom type in a PDB-style padded string.
bool get_is_selected(const PDBRecord &record) const override
Return true if the line should be processed.
Object(std::string name)
Construct an object with the given name.
Shared optimizer state that is invoked upon commitment of new coordinates.
Select all non-water non-alternative ATOM and HETATM records.
Select atoms which are selected by either or both selectors.
void write_multimodel_pdb(const Hierarchies &mhd, TextOutput out)
Select all hydrogen ATOM and HETATM records.
Select all CA ATOM records.
bool get_is_selected(const PDBRecord &record) const override
Return true if the line should be processed.
std::string get_chain_id(Hierarchy h)
Walk up the hierarchy to determine the chain id.
Element
The various elements currently supported/known.
Select which atoms to read from a PDB file.
std::string get_residue_name() const
Returns the residue type.
bool get_is_selected(const PDBRecord &record) const override
Return true if the line should be processed.
Select a subset of a hierarchy.
Select atoms which are selected by either selector but not both.
Select all ATOM and HETATM records with the given chain ids.
bool get_is_selected(const PDBRecord &record) const override
Return true if the line should be processed.
bool get_is_selected(const PDBRecord &record) const override
Return true if the line should be processed.
bool get_is_selected(const PDBRecord &record) const override
Return true if the line should be processed.