IMP logo
IMP Reference Guide  develop.7482b7c7af, 2026/12/05
The Integrative Modeling Platform
pdb.h
Go to the documentation of this file.
1/**
2 * \file IMP/atom/pdb.h
3 * \brief Functions to read PDBs
4 *
5 * Copyright 2007-2026 IMP Inventors. All rights reserved.
6 *
7 */
8
9#ifndef IMPATOM_PDB_H
10#define IMPATOM_PDB_H
11
12#include <IMP/atom/atom_config.h>
13#include "Hierarchy.h"
14#include "Atom.h"
15#include "element.h"
16#include "internal/pdb.h"
17#include "atom_macros.h"
18#include <IMP/file.h>
19#include "Selection.h"
20#include <IMP/Model.h>
21#include <IMP/Particle.h>
22#include <IMP/OptimizerState.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>
30#include <limits>
31
32IMPATOM_BEGIN_NAMESPACE
33
34//! Represent a single ATOM/HETATM "line" in PDB or mmCIF format
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_;
41public:
42 PDBRecord() : use_line_(false), use_keywords_(false) {}
43
44#ifndef SWIG
45 //! Point the record to a line of text from a PDB file
46 /** This uses a pointer to `line` so should not be used after line is freed */
47 void set_line(const std::string &line);
48
49 //! Point the record to a single atom_site loop row from an mmCIF file
50 /** This uses pointers to the CIF keywords, so should not be used after
51 the keywords are freed. */
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);
61#endif
62
63 //! Returns the alternative location indicator
64 /** This is a single character in PDB, but can be longer in mmCIF. */
65 std::string get_alt_loc_indicator() const;
66
67 //! Returns true if the record is an ATOM record
68 bool get_is_atom() const;
69
70 //! Returns the atom type as a string with no leading or trailing whitespace
71 std::string get_trimmed_atom_name() const;
72
73 //! Returns the atom type in a PDB-style padded string
74 /** The atom type is at least a 4 character long field.
75 The first character is space in many cases, but not always. */
76 std::string get_padded_atom_name() const;
77
78 //! Returns the residue type
79 std::string get_residue_name() const;
80
81 //! Returns the chain ID
82 /** This is a single character in PDB format, but can be longer in mmCIF.
83 In mmCIF, the author-provided chain ID is provided if available;
84 otherwise, the mmCIF asym_id is returned. */
85 std::string get_chain_id() const;
86
87 //! Returns the element as a string
88 std::string get_element() const;
89
90 //! Returns the residue number as an integer
91 int get_residue_number() const;
92
93 IMP_SHOWABLE_INLINE(PDBRecord, { out << "PDBRecord"; });
94};
96
97
98//! Select which atoms to read from a PDB file
99/** Selector is a general purpose class used to select records from a PDB
100 file. Using descendants of this class one may implement arbitrary
101 selection functions and pass them to PDB reading functions
102 for object selection. Simple selectors can be used to build more complicated
103 ones. Inheritance means "AND" unless otherwise noted (that is, the
104 CAlphaPDBSelector takes all non-alternate C-alphas since it inherits from
105 NonAlternativePDBSelector).
106
107 \see read_pdb, read_mmcif
108*/
109class IMPATOMEXPORT PDBSelector : public IMP::Object {
110 public:
111 PDBSelector(std::string name) : Object(name) {}
112 //! Return true if the line should be processed
113 virtual bool get_is_selected(const PDBRecord &record) const = 0;
114
115 virtual ~PDBSelector();
116};
117
119
120//! Select all ATOM and HETATM records which are not alternatives
121class NonAlternativePDBSelector : public PDBSelector {
122 public:
123 NonAlternativePDBSelector(std::string name = "NonAlternativePDBSelector%1%")
124 : PDBSelector(name) {}
125
126 bool get_is_selected(const PDBRecord &record) const override {
127 std::string alt_loc = record.get_alt_loc_indicator();
128 return (alt_loc == " " || alt_loc == "" || alt_loc == "A");
129 }
130 IMP_OBJECT_METHODS(NonAlternativePDBSelector);
131};
132
133//! Select all non-alternative ATOM records
134class ATOMPDBSelector : public NonAlternativePDBSelector {
135 public:
136 ATOMPDBSelector(std::string name = "ATOMPDBSelector%1%")
137 : NonAlternativePDBSelector(name) {}
138
139 bool get_is_selected(const PDBRecord &record) const override
140 {
142 record.get_is_atom());
143 }
144 IMP_OBJECT_METHODS(ATOMPDBSelector)
145};
146
147//! Select all CA ATOM records
148class CAlphaPDBSelector : public NonAlternativePDBSelector {
149 public:
150 CAlphaPDBSelector(std::string name = "CAlphaPDBSelector%1%")
151 : NonAlternativePDBSelector(name) {}
152
153 bool get_is_selected(const PDBRecord &record) const override {
154 if (!NonAlternativePDBSelector::get_is_selected(record)) return false;
155 const std::string type = record.get_padded_atom_name();
156 return (type[1] == 'C' && type[2] == 'A' && type[3] == ' ');
157 }
158 IMP_OBJECT_METHODS(CAlphaPDBSelector)
159};
160
161//! Select all CB ATOM records
162class CBetaPDBSelector : public NonAlternativePDBSelector {
163 public:
164 CBetaPDBSelector(std::string name = "CBetaPDBSelector%1%")
165 : NonAlternativePDBSelector(name) {}
166
167 bool get_is_selected(const PDBRecord &record) const override {
168 if (!NonAlternativePDBSelector::get_is_selected(record)) return false;
169 const std::string type = record.get_padded_atom_name();
170 return (type[1] == 'C' && type[2] == 'B' && type[3] == ' ');
171 }
172 IMP_OBJECT_METHODS(CBetaPDBSelector)
173};
174
175//! Select all atoms of the given types
176/** Note that unlike CAlphaPDBSelector and similar classes, this selects all
177 atoms, even those in alternative locations (combine with
178 a NonAlternativePDBSelector if necessary).
179 */
180class AtomTypePDBSelector : public PDBSelector {
181 Strings atom_types_;
182 public:
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());
187 }
188
189 bool get_is_selected(const PDBRecord &record) const override {
190 std::string type = record.get_trimmed_atom_name();
191 return std::binary_search(atom_types_.begin(), atom_types_.end(), type);
192 }
193 IMP_OBJECT_METHODS(AtomTypePDBSelector)
194};
195
196//! Select all atoms in residues of the given types
197/** Note that unlike CAlphaPDBSelector and similar classes, this selects all
198 atoms, even those in alternative locations (combine with
199 a NonAlternativePDBSelector if necessary).
200 */
201class ResidueTypePDBSelector : public PDBSelector {
202 Strings residue_types_;
203 public:
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());
208 }
209
210 bool get_is_selected(const PDBRecord &record) const override {
211 std::string type = record.get_residue_name();
212 return std::binary_search(residue_types_.begin(), residue_types_.end(),
213 type);
214 }
215 IMP_OBJECT_METHODS(ResidueTypePDBSelector)
216};
217
218//! Select all C (not CA or CB) ATOM records
219class CPDBSelector : public NonAlternativePDBSelector {
220 public:
221 CPDBSelector(std::string name = "CPDBSelector%1%")
222 : NonAlternativePDBSelector(name) {}
223
224 bool get_is_selected(const PDBRecord &record) const override {
225 if (!NonAlternativePDBSelector::get_is_selected(record)) return false;
226 const std::string type = record.get_padded_atom_name();
227 return (type[1] == 'C' && type[2] == ' ' && type[3] == ' ');
228 }
229 IMP_OBJECT_METHODS(CPDBSelector)
230};
231
232//! Select all N ATOM records
233class NPDBSelector : public NonAlternativePDBSelector {
234 public:
235 NPDBSelector(std::string name = "NPDBSelector%1%")
236 : NonAlternativePDBSelector(name) {}
237
238 bool get_is_selected(const PDBRecord &record) const override {
239 if (!NonAlternativePDBSelector::get_is_selected(record)) return false;
240 const std::string type = record.get_padded_atom_name();
241 return (type[1] == 'N' && type[2] == ' ' && type[3] == ' ');
242 }
243 IMP_OBJECT_METHODS(NPDBSelector)
244};
245
246//! Defines a selector that will pick every ATOM and HETATM record
247class AllPDBSelector : public PDBSelector {
248 public:
249 AllPDBSelector(std::string name = "AllPDBSelector%1%") : PDBSelector(name) {}
250
251 bool get_is_selected(const PDBRecord &) const override {
252 return true;
253 }
254 IMP_OBJECT_METHODS(AllPDBSelector);
255};
256
257//! Select all ATOM and HETATM records with the given chain ids
258/** When reading mmCIF format, this will use the author-provided chain
259 ID, if available; otherwise the mmCIF "chain" ID, label_asym_id,
260 will be used.
261 */
262class ChainPDBSelector : public NonAlternativePDBSelector {
263 public:
264 bool get_is_selected(const PDBRecord &record) const override {
266 return false;
267 }
268 std::string cid = record.get_chain_id();
269 return std::binary_search(chains_.begin(), chains_.end(), cid);
270 }
272
273 //! Allow any of the named chains
274 /** Chain IDs here, and in mmCIF files, can be any length,
275 although chains in legacy PDB files are restricted to
276 a single character.
277 */
279 std::string name = "ChainPDBSelector%1%")
280 : NonAlternativePDBSelector(name), chains_(chains) {
281 std::sort(chains_.begin(), chains_.end());
282 }
283
284 private:
285 Strings chains_;
286};
287
288//! Select all non-water ATOM and HETATM records
289class WaterPDBSelector : public NonAlternativePDBSelector {
290 public:
291 WaterPDBSelector(std::string name = "WaterPDBSelector%1%")
292 : NonAlternativePDBSelector(name) {}
293
294 bool get_is_selected(const PDBRecord &record) const override {
296 return false;
297 }
298 std::string res_name = record.get_residue_name();
299 return (res_name == "HOH" || res_name == "DOD");
300 }
301 IMP_OBJECT_METHODS(WaterPDBSelector)
302};
303
304//! Select all hydrogen ATOM and HETATM records
305class IMPATOMEXPORT HydrogenPDBSelector : public NonAlternativePDBSelector {
306 bool is_hydrogen(const PDBRecord &record) const;
307
308 public:
309 HydrogenPDBSelector(std::string name = "HydrogenPDBSelector%1%")
310 : NonAlternativePDBSelector(name) {}
311
312 bool get_is_selected(const PDBRecord &record) const override {
313 if (!NonAlternativePDBSelector::get_is_selected(record)) return false;
314 return is_hydrogen(record);
315 }
316 IMP_OBJECT_METHODS(HydrogenPDBSelector)
317};
318
319//! Select non water and non hydrogen atoms
320class NonWaterNonHydrogenPDBSelector : public NonAlternativePDBSelector {
322
323 public:
324 bool get_is_selected(const PDBRecord &record) const override {
326 return false;
327 }
328 return (!ws_->get_is_selected(record) && !hs_->get_is_selected(record));
329 }
330 IMP_OBJECT_METHODS(NonWaterNonHydrogenPDBSelector);
331 NonWaterNonHydrogenPDBSelector(std::string name)
332 : NonAlternativePDBSelector(name),
333 ws_(new WaterPDBSelector()),
334 hs_(new HydrogenPDBSelector()) {}
336 : NonAlternativePDBSelector("NonWaterPDBSelector%1%"),
337 ws_(new WaterPDBSelector()),
338 hs_(new HydrogenPDBSelector()) {}
339};
340
341//! Select non hydrogen atoms
342class NonHydrogenPDBSelector : public NonAlternativePDBSelector {
344
345 public:
346 bool get_is_selected(const PDBRecord &record) const override {
348 return false;
349 }
350 return (!hs_->get_is_selected(record));
351 }
352 IMP_OBJECT_METHODS(NonHydrogenPDBSelector);
353 NonHydrogenPDBSelector(std::string name)
354 : NonAlternativePDBSelector(name),
355 hs_(new HydrogenPDBSelector()) {}
357 : NonAlternativePDBSelector("NonHydrogenPDBSelector%1%"),
358 hs_(new HydrogenPDBSelector()) {}
359};
360
361//! Select all non-water non-alternative ATOM and HETATM records
362class NonWaterPDBSelector : public NonAlternativePDBSelector {
364
365 public:
366 bool get_is_selected(const PDBRecord &record) const override {
368 return false;
369 }
370 return (!ws_->get_is_selected(record));
371 }
372 IMP_OBJECT_METHODS(NonWaterPDBSelector);
373 NonWaterPDBSelector(std::string name)
374 : NonAlternativePDBSelector(name), ws_(new WaterPDBSelector()) {}
376 : NonAlternativePDBSelector("NonWaterPDBSelector%1%"),
377 ws_(new WaterPDBSelector()) {}
378};
379
380//! Select all backbone (N,CA,C,O) ATOM records
381class BackbonePDBSelector : public NonWaterNonHydrogenPDBSelector {
382 public:
383 BackbonePDBSelector(std::string name = "BackbonePDBSelector%1%")
384 : NonWaterNonHydrogenPDBSelector(name) {}
385
386 bool get_is_selected(const PDBRecord &record) const override {
388 return false;
389 const std::string type = record.get_padded_atom_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] == ' '));
394 }
395 IMP_OBJECT_METHODS(BackbonePDBSelector)
396};
397
398//! Select all P (= phosphate) ATOM records
399class PPDBSelector : public NonAlternativePDBSelector {
400 public:
401 PPDBSelector(std::string name = "PPDBSelector%1%")
402 : NonAlternativePDBSelector(name) {}
403
404 bool get_is_selected(const PDBRecord &record) const override {
405 if (!NonAlternativePDBSelector::get_is_selected(record)) return false;
406 const std::string type = record.get_padded_atom_name();
407 return (type[1] == 'P' && type[2] == ' ' && type[3] == ' ');
408 }
409 IMP_OBJECT_METHODS(PPDBSelector)
410};
411
412//! Select all residue numbers in the given range (inclusive)
413class ResidueRangePDBSelector : public PDBSelector {
414 int low_, high_;
415 public:
416 ResidueRangePDBSelector(int low, int high=std::numeric_limits<int>::max(),
417 std::string name = "ResidueRangePDBSelector%1%")
418 : PDBSelector(name), low_(low), high_(high) {}
419
420 bool get_is_selected(const PDBRecord &record) const override {
421 int resnum = record.get_residue_number();
422 return resnum >= low_ && resnum <= high_;
423 }
424 IMP_OBJECT_METHODS(ResidueRangePDBSelector)
425};
426
427//! Select atoms which are selected by both selectors
428/** To use do something like
429 \code
430 read_pdb(name, m, AndPDBSelector(PPDBSelector(), WaterPDBSelector()));
431 \endcode
432
433 In Python, the and operator (&) can be used to the same effect:
434 \code
435 read_pdb(name, m, PPDBSelector() & WaterPDBSelector());
436 \endcode
437 */
438class AndPDBSelector : public PDBSelector {
440
441 public:
442 bool get_is_selected(const PDBRecord &record) const override {
443 return a_->get_is_selected(record) && b_->get_is_selected(record);
444 }
445 IMP_OBJECT_METHODS(AndPDBSelector);
446 AndPDBSelector(PDBSelector *a, PDBSelector *b)
447 : PDBSelector("AndPDBSelector%1%"), a_(a), b_(b) {}
448};
449
450//! Select atoms which are selected by either or both selectors
451/** To use do something like
452 \code
453 read_pdb(name, m, OrPDBSelector(PPDBSelector(), WaterPDBSelector()));
454 \endcode
455
456 In Python, the or operator (|) can be used to the same effect:
457 \code
458 read_pdb(name, m, PPDBSelector() | WaterPDBSelector());
459 \endcode
460 */
461class OrPDBSelector : public PDBSelector {
463
464 public:
465 bool get_is_selected(const PDBRecord &record) const override {
466 return a_->get_is_selected(record) || b_->get_is_selected(record);
467 }
468 IMP_OBJECT_METHODS(OrPDBSelector);
469 OrPDBSelector(PDBSelector *a, PDBSelector *b)
470 : PDBSelector("OrPDBSelector%1%"), a_(a), b_(b) {}
471};
472
473//! Select atoms which are selected by either selector but not both
474/** To use do something like
475 \code
476 read_pdb(name, m, XorPDBSelector(HydrogenPDBSelector(),
477 WaterPDBSelector()));
478 \endcode
479
480 In Python, the xor operator (^) can be used to the same effect:
481 \code
482 read_pdb(name, m, HydrogenPDBSelector() ^ WaterPDBSelector());
483 \endcode
484 */
485class XorPDBSelector : public PDBSelector {
487
488 public:
489 bool get_is_selected(const PDBRecord &record) const override {
490 return a_->get_is_selected(record) != b_->get_is_selected(record);
491 }
492 IMP_OBJECT_METHODS(XorPDBSelector);
493 XorPDBSelector(PDBSelector *a, PDBSelector *b)
494 : PDBSelector("XorPDBSelector%1%"), a_(a), b_(b) {}
495};
496
497//! Select atoms which are not selected by a given selector
498/** To use do something like
499 \code
500 read_pdb(name, m, NotPDBSelector(PPDBSelector()));
501 \endcode
502
503 In Python, the inversion operator (~) can be used to the same effect:
504 \code
505 read_pdb(name, m, ~PPDBSelector());
506 \endcode
507 */
508class NotPDBSelector : public PDBSelector {
510
511 public:
512 bool get_is_selected(const PDBRecord &record) const override {
513 return !a_->get_is_selected(record);
514 }
515 IMP_OBJECT_METHODS(NotPDBSelector);
516 NotPDBSelector(PDBSelector *a) : PDBSelector("NotPDBSelector%1%"), a_(a) {}
517};
518
519/** @name PDB Reading
520 \anchor pdb_in
521 The read PDB methods produce a hierarchy that looks as follows:
522 - One Atom per ATOM or HETATM record in the PDB.
523 - All Atom particles have a parent which is a Residue.
524 - All Residue particles have a parent which is a Chain.
525
526 Waters are currently dropped if they are ATOM records. This can be fixed.
527
528 The read_pdb() functions should successfully parse all valid PDB files. It
529 can produce warnings on files which are not valid. It will attempt to read
530 such files, but all bets are off.
531
532 In order to track the provenance of IMP-generated models, the provenance
533 of any PDB files read in here - for example, the PDB id, or detail about
534 a comparative model - needs to also be tracked. This is done using the
535 PDB headers:
536 - Structures stored in the PDB database should keep the standard
537 `HEADER` record stating their PDB ID.
538 - Comparative models generated using MODELLER should include the
539 MODELLER-generated `EXPDTA` and `REMARK` records.
540 - Structures that are trivial modifications of an existing PDB structure
541 or comparative model should use the `TITLE` record to describe the
542 nature of the modification (e.g. rotation and translation) and one of
543 the two following custom `EXPDTA` record formats to point to the original
544 structure:
545 - `EXPDTA DERIVED FROM PDB:1XYZ`
546 - `EXPDTA DERIVED FROM COMPARATIVE MODEL, DOI:x.y/z`
547 - Structures generated from multiple sources (e.g. two structures that
548 have been docked and then concatenated into a single PDB file) are not
549 allowed. Store each constituent structure in its own file and annotate
550 each one with a suitable `EXPDTA` record, as above.
551 Note that while provenance of PDB files is not currently enforced, it
552 likely will be in future IMP releases.
553
554 When reading PDBs, PDBSelector objects can be used to choose to only process
555 certain record types. See the class documentation for more information.
556 When no PDB selector is supplied for reading, the
557 NonWaterPDBSelector is used.
558
559 Set the IMP::LogLevel to VERBOSE to see details of parse errors.
560*/
561//!@{
562
563inline PDBSelector *get_default_pdb_selector() {
564 return new NonWaterPDBSelector();
565}
566
567//! Read all the molecules in the first model of the PDB file.
568/** \param[in] input The file or stream to read the model from.
569 \param[in] model The IMP::Model object to read into.
570 \param[in] selector A PDBSelector object used to read only
571 part of the model (e.g. only a single chain).
572 \param[in] select_first_model When reading a multi-model file (with
573 multiple MODEL/ENDMDL records) read only the first model if
574 set true. If set false, combine all models into a single
575 hierarchy (see read_multimodel_pdb to read each model into
576 a separate hierarchy).
577 \return a molecular hierarchy corresponding to the PDB model
578 */
579IMPATOMEXPORT Hierarchy
580 read_pdb(TextInput input, Model *model,
581 PDBSelector *selector = get_default_pdb_selector(),
582 bool select_first_model = true
583#ifndef IMP_DOXYGEN
584 ,
585 bool no_radii = false
586#endif
587 );
588
589/** Rewrite the coordinates of the passed hierarchy based
590 on the contents of the first model in the PDB file.
591
592 The hierarchy must have been created by reading from a PDB
593 file and the atom numbers must correspond between the files.
594 These are not really checked.
595
596 A ValueException is thrown if there are insufficient models
597 in the file.
598
599 core::RigidMember particles are handled by updating the
600 core::RigidBody algebra::ReferenceFrame3D to align with the
601 loaded particles. Bad things will happen if the loaded coordinates
602 are not a rigid transform of the prior coordinates.
603 */
604IMPATOMEXPORT void read_pdb(TextInput input, int model, Hierarchy h);
605
606/** Read all models from the PDB file.
607 */
608IMPATOMEXPORT Hierarchies
610 PDBSelector *selector = get_default_pdb_selector()
611#ifndef IMP_DOXYGEN
612 ,
613 bool noradii = false
614#endif
615 );
616
617/** @name PDB Writing
618 \anchor pdb_out
619 The methods to write a PDB expects a Hierarchy that looks as follows:
620 - all leaves are Atom particles
621 - all Atom particles have Residue particles as parents
622
623 All Residue particles that have a Chain particle as an ancestor
624 are considered part of a protein, DNA or RNA, ones without are
625 considered heterogens.
626
627 The functions produce files that are not valid PDB files,
628 eg only ATOM/HETATM lines are printed for all Atom particles
629 in the hierarchy. Complain if your favorite program can't read them and
630 we might fix it.
631*/
632//!@{
633
634/** Write some atoms to a PDB.
635*/
636IMPATOMEXPORT void write_pdb(const Selection &mhd, TextOutput out,
637 unsigned int model = 1);
638
639/** \brief Write a hierarchy to a PDB as C_alpha atoms.
640
641 This method is used to write a non-atomic hierarchy into a PDB in a way
642 that can be read by most programs. If the leaves are Residue particles
643 then the index and residue type will be read from them. Otherwise default
644 values will be used so that each leaf ends up in a separate residue.
645*/
646IMPATOMEXPORT void write_pdb_of_c_alphas(const Selection &mhd,
647 TextOutput out,
648 unsigned int model = 1);
649
650/** Write the hierarchies one per frame.
651*/
652IMPATOMEXPORT void write_multimodel_pdb(const Hierarchies &mhd,
653 TextOutput out);
654/** @} */
655
656#ifndef IMP_DOXYGEN
657
658/**
659 This function returns a string in PDB ATOM format
660*/
661IMPATOMEXPORT std::string get_pdb_string(
662 const algebra::Vector3D &v, int index = -1, AtomType at = AT_CA,
663 ResidueType rt = atom::ALA, char chain = ' ', int res_index = 1,
664 char res_icode = ' ', double occupancy = 1.00, double tempFactor = 0.00,
665 Element e = C);
666
667/**
668 This function returns a connectivity string in PDB format
669 \note The CONECT records specify connectivity between atoms for which
670 coordinates are supplied. The connectivity is described using
671 the atom serial number as found in the entry.
672 \note http://www.bmsc.washington.edu/CrystaLinks/man/pdb/guide2.2_frame.html
673*/
674IMPATOMEXPORT std::string get_pdb_conect_record_string(int, int);
675#endif
676
677/** \class WritePDBOptimizerState
678 This writes a PDB file at the specified interval during optimization.
679 If the file name contains %1% then a new file is written each time
680 with the %1% replaced by the index. Otherwise a new model is written
681 each time to the same file.
682*/
683class IMPATOMEXPORT WritePDBOptimizerState : public OptimizerState {
684 std::string filename_;
685 ParticleIndexes pis_;
686
687 friend class cereal::access;
688
689 template<class Archive> void serialize(Archive &ar) {
690 ar(cereal::base_class<OptimizerState>(this), filename_, pis_);
691 }
692 IMP_OBJECT_SERIALIZE_DECL(WritePDBOptimizerState);
693
694 public:
695 WritePDBOptimizerState(Model *m,
696 const ParticleIndexesAdaptor &pis,
697 std::string filename);
698 WritePDBOptimizerState(const atom::Hierarchies mh, std::string filename);
699 WritePDBOptimizerState() {}
700
701 protected:
702 virtual void do_update(unsigned int call) override;
703 virtual ModelObjectsTemp do_get_inputs() const override;
704 IMP_OBJECT_METHODS(WritePDBOptimizerState);
705};
706
707IMPATOM_END_NAMESPACE
708
709#endif /* IMPATOM_PDB_H */
Simple atom decorator.
Storage of a model, its restraints, constraints and particles.
Shared optimizer state.
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.
Definition Model.h:111
Common base class for heavy weight IMP objects.
Definition Object.h:111
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.
Definition pdb.h:139
bool get_is_selected(const PDBRecord &) const override
Return true if the line should be processed.
Definition pdb.h:251
bool get_is_selected(const PDBRecord &record) const override
Return true if the line should be processed.
Definition pdb.h:442
bool get_is_selected(const PDBRecord &record) const override
Return true if the line should be processed.
Definition pdb.h:189
bool get_is_selected(const PDBRecord &record) const override
Return true if the line should be processed.
Definition pdb.h:386
bool get_is_selected(const PDBRecord &record) const override
Return true if the line should be processed.
Definition pdb.h:153
bool get_is_selected(const PDBRecord &record) const override
Return true if the line should be processed.
Definition pdb.h:167
bool get_is_selected(const PDBRecord &record) const override
Return true if the line should be processed.
Definition pdb.h:224
bool get_is_selected(const PDBRecord &record) const override
Return true if the line should be processed.
Definition pdb.h:264
ChainPDBSelector(Strings chains, std::string name="ChainPDBSelector%1%")
Allow any of the named chains.
Definition pdb.h:278
The standard decorator for manipulating molecular structures.
Select all hydrogen ATOM and HETATM records.
Definition pdb.h:305
bool get_is_selected(const PDBRecord &record) const override
Return true if the line should be processed.
Definition pdb.h:312
bool get_is_selected(const PDBRecord &record) const override
Return true if the line should be processed.
Definition pdb.h:238
Select all ATOM and HETATM records which are not alternatives.
Definition pdb.h:121
bool get_is_selected(const PDBRecord &record) const override
Return true if the line should be processed.
Definition pdb.h:126
Select non hydrogen atoms.
Definition pdb.h:342
bool get_is_selected(const PDBRecord &record) const override
Return true if the line should be processed.
Definition pdb.h:346
Select non water and non hydrogen atoms.
Definition pdb.h:320
bool get_is_selected(const PDBRecord &record) const override
Return true if the line should be processed.
Definition pdb.h:324
Select all non-water non-alternative ATOM and HETATM records.
Definition pdb.h:362
bool get_is_selected(const PDBRecord &record) const override
Return true if the line should be processed.
Definition pdb.h:366
bool get_is_selected(const PDBRecord &record) const override
Return true if the line should be processed.
Definition pdb.h:512
bool get_is_selected(const PDBRecord &record) const override
Return true if the line should be processed.
Definition pdb.h:465
Represent a single ATOM/HETATM "line" in PDB or mmCIF format.
Definition pdb.h:35
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.
Definition pdb.h:109
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.
Definition pdb.h:404
bool get_is_selected(const PDBRecord &record) const override
Return true if the line should be processed.
Definition pdb.h:420
bool get_is_selected(const PDBRecord &record) const override
Return true if the line should be processed.
Definition pdb.h:210
Select hierarchy particles identified by the biological name.
Definition Selection.h:76
Select all non-water ATOM and HETATM records.
Definition pdb.h:289
bool get_is_selected(const PDBRecord &record) const override
Return true if the line should be processed.
Definition pdb.h:294
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.
Definition pdb.h:489
Define the elements used in IMP.
Handling of file input/output.
IMP::Vector< PDBRecord > PDBRecords
Definition pdb.h:95
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.
Definition element.h:23
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)
const AtomType AT_CA
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
Definition pdb.h:118
Vector< ParticleIndex, std::allocator< ParticleIndex > > ParticleIndexes
A list of particles, each identified by its ParticleIndex.
Definition base_types.h:199
VectorD< 3 > Vector3D
Definition VectorD.h:407
IMP::Vector< String > Strings
Standard way to pass a bunch of String values.
Definition types.h:50
IMP::Vector< IMP::WeakPointer< ModelObject > > ModelObjectsTemp
Definition base_types.h:122
#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.
Definition Pointer.h:144
#define IMP_VALUES(Name, PluralName)
Define the type for storing sets of values.