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>
32 IMPATOM_BEGIN_NAMESPACE
36 const std::string *line_;
37 internal::StringCifKeyword *group_, *element_, *atom_name_, *alt_loc_id_,
38 *residue_name_, *auth_chain_, *chain_, *auth_seq_id_;
39 internal::IntCifKeyword *seq_id_;
40 bool use_line_, use_keywords_;
42 PDBRecord() : use_line_(
false), use_keywords_(
false) {}
47 void set_line(
const std::string &line);
52 void set_keywords(internal::StringCifKeyword &group,
53 internal::StringCifKeyword &element,
54 internal::StringCifKeyword &atom_name,
55 internal::StringCifKeyword &alt_loc_id,
56 internal::StringCifKeyword &residue_name,
57 internal::StringCifKeyword &auth_chain,
58 internal::StringCifKeyword &chain,
59 internal::IntCifKeyword &seq_id,
60 internal::StringCifKeyword &auth_seq_id);
65 std::string get_alt_loc_indicator()
const;
68 bool get_is_atom()
const;
71 std::string get_trimmed_atom_name()
const;
76 std::string get_padded_atom_name()
const;
79 std::string get_residue_name()
const;
88 std::string get_element()
const;
91 int get_residue_number()
const;
113 virtual bool get_is_selected(
const PDBRecord &record)
const = 0;
128 return (alt_loc ==
" " || alt_loc ==
"" || alt_loc ==
"A");
141 return (NonAlternativePDBSelector::get_is_selected(record) &&
154 if (!NonAlternativePDBSelector::get_is_selected(record))
return false;
156 return (type[1] ==
'C' && type[2] ==
'A' && type[3] ==
' ');
168 if (!NonAlternativePDBSelector::get_is_selected(record))
return false;
170 return (type[1] ==
'C' && type[2] ==
'B' && type[3] ==
' ');
184 std::string name =
"AtomTypePDBSelector%1%")
186 std::sort(atom_types_.begin(), atom_types_.end());
191 return std::binary_search(atom_types_.begin(), atom_types_.end(), type);
205 std::string name =
"ResidueTypePDBSelector%1%")
206 :
PDBSelector(name), residue_types_(residue_types) {
207 std::sort(residue_types_.begin(), residue_types_.end());
212 return std::binary_search(residue_types_.begin(), residue_types_.end(),
225 if (!NonAlternativePDBSelector::get_is_selected(record))
return false;
227 return (type[1] ==
'C' && type[2] ==
' ' && type[3] ==
' ');
239 if (!NonAlternativePDBSelector::get_is_selected(record))
return false;
241 return (type[1] ==
'N' && type[2] ==
' ' && type[3] ==
' ');
265 if (!NonAlternativePDBSelector::get_is_selected(record)) {
269 return std::binary_search(chains_.begin(), chains_.end(), cid);
279 std::string name =
"ChainPDBSelector%1%")
281 std::sort(chains_.begin(), chains_.end());
295 if (!NonAlternativePDBSelector::get_is_selected(record)) {
299 return (res_name ==
"HOH" || res_name ==
"DOD");
306 bool is_hydrogen(
const PDBRecord &record)
const;
313 if (!NonAlternativePDBSelector::get_is_selected(record))
return false;
314 return is_hydrogen(record);
325 if (!NonAlternativePDBSelector::get_is_selected(record)) {
328 return (!ws_->get_is_selected(record) && !hs_->get_is_selected(record));
347 if (!NonAlternativePDBSelector::get_is_selected(record)) {
350 return (!hs_->get_is_selected(record));
367 if (!NonAlternativePDBSelector::get_is_selected(record)) {
370 return (!ws_->get_is_selected(record));
387 if (!NonWaterNonHydrogenPDBSelector::get_is_selected(record))
390 return ((type[1] ==
'N' && type[2] ==
' ' && type[3] ==
' ') ||
391 (type[1] ==
'C' && type[2] ==
'A' && type[3] ==
' ') ||
392 (type[1] ==
'C' && type[2] ==
' ' && type[3] ==
' ') ||
393 (type[1] ==
'O' && type[2] ==
' ' && type[3] ==
' '));
405 if (!NonAlternativePDBSelector::get_is_selected(record))
return false;
407 return (type[1] ==
'P' && type[2] ==
' ' && type[3] ==
' ');
417 std::string name =
"ResidueRangePDBSelector%1%")
422 return resnum >= low_ && resnum <= high_;
443 return a_->get_is_selected(record) && b_->get_is_selected(record);
447 :
PDBSelector(
"AndPDBSelector%1%"), a_(a), b_(b) {}
466 return a_->get_is_selected(record) || b_->get_is_selected(record);
490 return a_->get_is_selected(record) != b_->get_is_selected(record);
494 :
PDBSelector(
"XorPDBSelector%1%"), a_(a), b_(b) {}
513 return !a_->get_is_selected(record);
563 inline PDBSelector *get_default_pdb_selector() {
564 return new NonWaterPDBSelector();
579 IMPATOMEXPORT Hierarchy
580 read_pdb(TextInput input, Model *model,
581 PDBSelector *selector = get_default_pdb_selector(),
582 bool select_first_model =
true
585 bool no_radii =
false
604 IMPATOMEXPORT
void read_pdb(TextInput input,
int model, Hierarchy h);
608 IMPATOMEXPORT Hierarchies
610 PDBSelector *selector = get_default_pdb_selector()
636 IMPATOMEXPORT
void write_pdb(
const Selection &mhd, TextOutput out,
637 unsigned int model = 1);
648 unsigned int model = 1);
661 IMPATOMEXPORT std::string get_pdb_string(
663 ResidueType rt = atom::ALA,
char chain =
' ',
int res_index = 1,
664 char res_icode =
' ',
double occupancy = 1.00,
double tempFactor = 0.00,
674 IMPATOMEXPORT std::string get_pdb_conect_record_string(
int,
int);
684 std::string filename_;
687 friend class cereal::access;
689 template<
class Archive>
void serialize(Archive &ar) {
690 ar(cereal::base_class<OptimizerState>(
this), filename_, pis_);
697 std::string filename);
702 virtual void do_update(
unsigned int call)
override;
707 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.
Select all residue numbers in the given range (inclusive)
#define IMP_SHOWABLE_INLINE(Name, how_to_show)
Declare the methods needed by an object that can be printed.
bool get_is_selected(const PDBRecord &record) const override
Return true if the line should be processed.
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.
int get_residue_number() const
Returns the residue number as an integer.
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.