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>
32IMPATOM_BEGIN_NAMESPACE
35class IMPATOMEXPORT PDBRecord :
public Value {
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) {}
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);
111 PDBSelector(std::string name) :
Object(name) {}
115 virtual ~PDBSelector();
121class NonAlternativePDBSelector :
public PDBSelector {
123 NonAlternativePDBSelector(std::string name =
"NonAlternativePDBSelector%1%")
124 : PDBSelector(name) {}
128 return (alt_loc ==
" " || alt_loc ==
"" || alt_loc ==
"A");
134class ATOMPDBSelector :
public NonAlternativePDBSelector {
136 ATOMPDBSelector(std::string name =
"ATOMPDBSelector%1%")
137 : NonAlternativePDBSelector(name) {}
148class CAlphaPDBSelector :
public NonAlternativePDBSelector {
150 CAlphaPDBSelector(std::string name =
"CAlphaPDBSelector%1%")
151 : NonAlternativePDBSelector(name) {}
156 return (type[1] ==
'C' && type[2] ==
'A' && type[3] ==
' ');
162class CBetaPDBSelector :
public NonAlternativePDBSelector {
164 CBetaPDBSelector(std::string name =
"CBetaPDBSelector%1%")
165 : NonAlternativePDBSelector(name) {}
170 return (type[1] ==
'C' && type[2] ==
'B' && type[3] ==
' ');
180class AtomTypePDBSelector :
public PDBSelector {
183 AtomTypePDBSelector(
Strings atom_types,
184 std::string name =
"AtomTypePDBSelector%1%")
185 : PDBSelector(name), atom_types_(atom_types) {
186 std::sort(atom_types_.begin(), atom_types_.end());
191 return std::binary_search(atom_types_.begin(), atom_types_.end(), type);
201class ResidueTypePDBSelector :
public PDBSelector {
204 ResidueTypePDBSelector(
Strings residue_types,
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(),
219class CPDBSelector :
public NonAlternativePDBSelector {
221 CPDBSelector(std::string name =
"CPDBSelector%1%")
222 : NonAlternativePDBSelector(name) {}
227 return (type[1] ==
'C' && type[2] ==
' ' && type[3] ==
' ');
233class NPDBSelector :
public NonAlternativePDBSelector {
235 NPDBSelector(std::string name =
"NPDBSelector%1%")
236 : NonAlternativePDBSelector(name) {}
241 return (type[1] ==
'N' && type[2] ==
' ' && type[3] ==
' ');
247class AllPDBSelector :
public PDBSelector {
249 AllPDBSelector(std::string name =
"AllPDBSelector%1%") : PDBSelector(name) {}
269 return std::binary_search(chains_.begin(), chains_.end(), cid);
279 std::string name =
"ChainPDBSelector%1%")
280 : NonAlternativePDBSelector(name), chains_(chains) {
281 std::sort(chains_.begin(), chains_.end());
289class WaterPDBSelector :
public NonAlternativePDBSelector {
291 WaterPDBSelector(std::string name =
"WaterPDBSelector%1%")
292 : NonAlternativePDBSelector(name) {}
299 return (res_name ==
"HOH" || res_name ==
"DOD");
305class IMPATOMEXPORT HydrogenPDBSelector :
public NonAlternativePDBSelector {
306 bool is_hydrogen(
const PDBRecord &record)
const;
309 HydrogenPDBSelector(std::string name =
"HydrogenPDBSelector%1%")
310 : NonAlternativePDBSelector(name) {}
314 return is_hydrogen(record);
320class NonWaterNonHydrogenPDBSelector :
public NonAlternativePDBSelector {
328 return (!ws_->get_is_selected(record) && !hs_->get_is_selected(record));
331 NonWaterNonHydrogenPDBSelector(std::string name)
332 : NonAlternativePDBSelector(name),
342class NonHydrogenPDBSelector :
public NonAlternativePDBSelector {
350 return (!hs_->get_is_selected(record));
353 NonHydrogenPDBSelector(std::string name)
354 : NonAlternativePDBSelector(name),
362class NonWaterPDBSelector :
public NonAlternativePDBSelector {
370 return (!ws_->get_is_selected(record));
373 NonWaterPDBSelector(std::string name)
381class BackbonePDBSelector :
public NonWaterNonHydrogenPDBSelector {
383 BackbonePDBSelector(std::string name =
"BackbonePDBSelector%1%")
384 : NonWaterNonHydrogenPDBSelector(name) {}
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] ==
' '));
399class PPDBSelector :
public NonAlternativePDBSelector {
401 PPDBSelector(std::string name =
"PPDBSelector%1%")
402 : NonAlternativePDBSelector(name) {}
407 return (type[1] ==
'P' && type[2] ==
' ' && type[3] ==
' ');
413class ResidueRangePDBSelector :
public PDBSelector {
416 ResidueRangePDBSelector(
int low,
int high=std::numeric_limits<int>::max(),
417 std::string name =
"ResidueRangePDBSelector%1%")
418 : PDBSelector(name), low_(low), high_(high) {}
422 return resnum >= low_ && resnum <= high_;
438class AndPDBSelector :
public PDBSelector {
443 return a_->get_is_selected(record) && b_->get_is_selected(record);
446 AndPDBSelector(PDBSelector *a, PDBSelector *b)
447 : PDBSelector(
"AndPDBSelector%1%"), a_(a), b_(b) {}
461class OrPDBSelector :
public PDBSelector {
466 return a_->get_is_selected(record) || b_->get_is_selected(record);
469 OrPDBSelector(PDBSelector *a, PDBSelector *b)
470 : PDBSelector(
"OrPDBSelector%1%"), a_(a), b_(b) {}
485class XorPDBSelector :
public PDBSelector {
490 return a_->get_is_selected(record) != b_->get_is_selected(record);
493 XorPDBSelector(PDBSelector *a, PDBSelector *b)
494 : PDBSelector(
"XorPDBSelector%1%"), a_(a), b_(b) {}
508class NotPDBSelector :
public PDBSelector {
513 return !a_->get_is_selected(record);
516 NotPDBSelector(PDBSelector *a) : PDBSelector(
"NotPDBSelector%1%"), a_(a) {}
563inline PDBSelector *get_default_pdb_selector() {
564 return new NonWaterPDBSelector();
579IMPATOMEXPORT Hierarchy
581 PDBSelector *selector = get_default_pdb_selector(),
582 bool select_first_model =
true
585 bool no_radii =
false
608IMPATOMEXPORT Hierarchies
637 unsigned int model = 1);
648 unsigned int model = 1);
661IMPATOMEXPORT 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,
674IMPATOMEXPORT 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_);
695 WritePDBOptimizerState(Model *m,
697 std::string filename);
698 WritePDBOptimizerState(
const atom::Hierarchies mh, std::string filename);
699 WritePDBOptimizerState() {}
Storage of a model, its restraints, constraints and particles.
Classes to handle individual model particles. (Note that implementation of inline functions is in int...
Select a subset of a hierarchy.
Decorator for helping deal with a hierarchy of molecules.
Macros for maintaining molecular hierarchies.
Class for storing model, its restraints, constraints, and particles.
Common base class for heavy weight IMP objects.
Object(std::string name)
Construct an object with the given name.
OptimizerState(Model *m, std::string name)
Constructor.
Take Decorator, Particle or ParticleIndex.
bool get_is_selected(const PDBRecord &record) const override
Return true if the line should be processed.
bool get_is_selected(const PDBRecord &) 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.
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.
ChainPDBSelector(Strings chains, std::string name="ChainPDBSelector%1%")
Allow any of the named chains.
The standard decorator for manipulating molecular structures.
Select all hydrogen ATOM and HETATM records.
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.
Select all ATOM and HETATM records which are not alternatives.
bool get_is_selected(const PDBRecord &record) const override
Return true if the line should be processed.
Select non hydrogen atoms.
bool get_is_selected(const PDBRecord &record) const override
Return true if the line should be processed.
Select non water and non hydrogen atoms.
bool get_is_selected(const PDBRecord &record) const override
Return true if the line should be processed.
Select all non-water non-alternative ATOM and HETATM records.
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.
Represent a single ATOM/HETATM "line" in PDB or mmCIF format.
void set_line(const std::string &line)
Point the record to a line of text from a PDB file.
std::string get_chain_id() const
Returns the chain ID.
std::string get_residue_name() const
Returns the residue type.
void set_keywords(internal::StringCifKeyword &group, internal::StringCifKeyword &element, internal::StringCifKeyword &atom_name, internal::StringCifKeyword &alt_loc_id, internal::StringCifKeyword &residue_name, internal::StringCifKeyword &auth_chain, internal::StringCifKeyword &chain, internal::IntCifKeyword &seq_id, internal::StringCifKeyword &auth_seq_id)
Point the record to a single atom_site loop row from an mmCIF file.
std::string get_element() const
Returns the element as a string.
bool get_is_atom() const
Returns true if the record is an ATOM record.
std::string get_trimmed_atom_name() const
Returns the atom type as a string with no leading or trailing whitespace.
std::string get_padded_atom_name() const
Returns the atom type in a PDB-style padded string.
std::string get_alt_loc_indicator() const
Returns the alternative location indicator.
int get_residue_number() const
Returns the residue number as an integer.
Select which atoms to read from a PDB file.
virtual bool get_is_selected(const PDBRecord &record) const =0
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.
Select hierarchy particles identified by the biological name.
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.
virtual void do_update(unsigned int call) override
virtual ModelObjectsTemp do_get_inputs() const override
bool get_is_selected(const PDBRecord &record) const override
Return true if the line should be processed.
Define the elements used in IMP.
Handling of file input/output.
IMP::Vector< PDBRecord > PDBRecords
void write_multimodel_pdb(const Hierarchies &mhd, TextOutput out)
Hierarchies read_multimodel_pdb(TextInput input, Model *model, PDBSelector *selector=get_default_pdb_selector())
Element
The various elements currently supported/known.
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.
void write_pdb(const Selection &mhd, TextOutput out, unsigned int model=1)
Hierarchy read_pdb(TextInput input, Model *model, PDBSelector *selector=get_default_pdb_selector(), bool select_first_model=true)
Read all the molecules in the first model of the PDB file.
IMP::Vector< IMP::Pointer< PDBSelector > > PDBSelectors
Vector< ParticleIndex, std::allocator< ParticleIndex > > ParticleIndexes
A list of particles, each identified by its ParticleIndex.
IMP::Vector< String > Strings
Standard way to pass a bunch of String values.
IMP::Vector< IMP::WeakPointer< ModelObject > > ModelObjectsTemp
#define IMP_OBJECT_SERIALIZE_DECL(Name)
Declare methods needed for serialization of Object pointers.
#define IMP_OBJECTS(Name, PluralName)
Define the types for storing lists of object pointers.
#define IMP_OBJECT_METHODS(Name)
Define the basic things needed by any Object.
#define IMP_SHOWABLE_INLINE(Name, how_to_show)
Declare the methods needed by an object that can be printed.
A smart pointer to a ref-counted Object that is a class member.
#define IMP_VALUES(Name, PluralName)
Define the type for storing sets of values.