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());
289 if (!NonAlternativePDBSelector::get_is_selected(record)) {
293 return (res_name ==
"HOH" || res_name ==
"DOD");
300 bool is_hydrogen(
const PDBRecord &record)
const;
307 if (!NonAlternativePDBSelector::get_is_selected(record))
return false;
308 return is_hydrogen(record);
319 if (!NonAlternativePDBSelector::get_is_selected(record)) {
322 return (!ws_->get_is_selected(record) && !hs_->get_is_selected(record));
341 if (!NonAlternativePDBSelector::get_is_selected(record)) {
344 return (!hs_->get_is_selected(record));
361 if (!NonAlternativePDBSelector::get_is_selected(record)) {
364 return (!ws_->get_is_selected(record));
381 if (!NonWaterNonHydrogenPDBSelector::get_is_selected(record))
384 return ((type[1] ==
'N' && type[2] ==
' ' && type[3] ==
' ') ||
385 (type[1] ==
'C' && type[2] ==
'A' && type[3] ==
' ') ||
386 (type[1] ==
'C' && type[2] ==
' ' && type[3] ==
' ') ||
387 (type[1] ==
'O' && type[2] ==
' ' && type[3] ==
' '));
399 if (!NonAlternativePDBSelector::get_is_selected(record))
return false;
401 return (type[1] ==
'P' && type[2] ==
' ' && type[3] ==
' ');
422 return a_->get_is_selected(record) && b_->get_is_selected(record);
426 :
PDBSelector(
"AndPDBSelector%1%"), a_(a), b_(b) {}
445 return a_->get_is_selected(record) || b_->get_is_selected(record);
469 return a_->get_is_selected(record) != b_->get_is_selected(record);
473 :
PDBSelector(
"XorPDBSelector%1%"), a_(a), b_(b) {}
492 return !a_->get_is_selected(record);
542 inline PDBSelector *get_default_pdb_selector() {
543 return new NonWaterPDBSelector();
558 IMPATOMEXPORT Hierarchy
559 read_pdb(TextInput input, Model *model,
560 PDBSelector *selector = get_default_pdb_selector(),
561 bool select_first_model =
true
564 bool no_radii =
false
583 IMPATOMEXPORT
void read_pdb(TextInput input,
int model, Hierarchy h);
587 IMPATOMEXPORT Hierarchies
589 PDBSelector *selector = get_default_pdb_selector()
615 IMPATOMEXPORT
void write_pdb(
const Selection &mhd, TextOutput out,
616 unsigned int model = 1);
627 unsigned int model = 1);
640 IMPATOMEXPORT std::string get_pdb_string(
642 ResidueType rt = atom::ALA,
char chain =
' ',
int res_index = 1,
643 char res_icode =
' ',
double occupancy = 1.00,
double tempFactor = 0.00,
653 IMPATOMEXPORT std::string get_pdb_conect_record_string(
int,
int);
663 std::string filename_;
666 friend class cereal::access;
668 template<
class Archive>
void serialize(Archive &ar) {
669 ar(cereal::base_class<OptimizerState>(
this), filename_, pis_);
676 std::string filename);
681 virtual void do_update(
unsigned int call)
override;
686 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.
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.