BALL  1.4.79
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
NMRStarFile.h
Go to the documentation of this file.
1 // -*- Mode: C++; tab-width: 2; -*-
2 // vi: set ts=2:
3 //
4 
5 #ifndef BALL_FORMAT_NMRSTARFILE_H
6 #define BALL_FORMAT_NMRSTARFILE_H
7 
8 #ifndef BALL_FORMAT_CIFFILE_H
9 # include <BALL/FORMAT/CIFFile.h>
10 #endif
11 
12 #ifndef BALL_KERNEL_PROTEIN_H
13 # include <BALL/KERNEL/protein.h>
14 #endif
15 
16 #ifndef BALL_STRUCTURE_PEPTIDES_H
17 # include <BALL/STRUCTURE/peptides.h>
18 #endif
19 
20 #include <vector>
21 
22 namespace BALL
23 {
114  : public CIFFile
115  {
116  public:
117 
118  // constant variables to denote unknown values
119  static const float FLOAT_VALUE_NA;
120  static const int INT_VALUE_NA;
121 
123 
129 
136  {
137  public:
138  SampleCondition();
139 
140  // saveframe name -- referenced in the sample_condition_label
141  // of the saveframe "assigned_chemical_shifts"
143  // Accoring to the NMRStarFile 2.1 documentation
144  // the first entry MUST BE "_Variable_type".
145  // This is why we are allowed to map per type :-)
146  vector<String> types;
150 
151  bool hasType(String type) {return values.has(type);}
152  std::ostream& operator >> (std::ostream& s);
153  };
154 
159  {
160  public:
161 
167  {
168  public:
169  Component();
170  void clear();
171 
178 
179  std::ostream& operator >> (std::ostream& s);
180  };
181 
182  Sample();
183  void clear();
184 
188  vector <Component> components;
189 
190  std::ostream& operator >> (std::ostream& s);
191  };
192 
199  {
200  public:
202 
208  float shift_value;
212 
213  std::ostream& operator >> (std::ostream& s);
214  };
215 
222  {
223  public:
225 
226  // The saveframe's name = set name
227  // can be referenced in the saveframe "assigned_chemical_shifts"
229  std::vector<ShiftReferenceElement> elements;
230 
231  std::ostream& operator >> (std::ostream& s);
232  };
233 
240  {
241  public:
242  NMRAtomData();
243 
248  char atom_type;
249  float shift_value;
250  float error_value;
252 
253  bool operator == (const NMRAtomData& atom) const;
254  std::ostream& operator >> (std::ostream& s);
255  };
256 
257 
267  class BALL_EXPORT NMRAtomDataSet // _Saveframe_category assigned_chemical_shifts
268 
269  {
270  public:
271  NMRAtomDataSet(NMRStarFile* parent);
272 
275  std::vector<NMRAtomData> atom_data;
278  std::vector<String> samples;
279 
280  std::ostream& operator >> (std::ostream& s);
281 
282  protected:
284  };
285 
292  {
293  public:
295  ~EntryInformation();
296 
297  std::ostream& operator >> (std::ostream& s);
298  void clear();
299 
305 
306  };
307 
313  {
314  public:
317  {
318  public:
319  HomologDB();
320 
321  std::ostream& operator >> (std::ostream& s);
322  void clear();
323 
332  };
333 
334 
336 
344  // polymer residue sequence information
347  // we want to allow things like resid 137A, so we cannot use Index
348  // key: index -- value: aminoacidname
350  vector<HomologDB> homolog_database_entries;
351 
352  std::ostream& operator >> (std::ostream& s);
353  void clear();
354  };
355 
356 
362  {
363  // System related information
364  public:
366  {
367  public:
368  RelatedDB();
369 
370  std::ostream& operator >> (std::ostream& s);
371  void clear();
372 
378  };
379 
380 
381  // Central class for convenience
383  {
384  public:
385  ChemicalUnit();
386  std::ostream& operator >> (std::ostream& s);
387  void clear();
388 
393  };
394 
395 
396  MolecularSystem();
397  ~MolecularSystem();
398 
399  ChemicalUnit const& getChemicalUnit(Position i) const { return chemical_units[i]; }
400  ChemicalUnit& getChemicalUnit(Position i) { return chemical_units[i]; }
401 
402  Size getNumberOfChemicalUnits() const {return chemical_units.size(); }
403 
404  // Name of the molecular system
407  vector<ChemicalUnit> chemical_units;
414  // related entries in various DB's
415  vector<RelatedDB> related_database_entries;
416 
418 
419  std::ostream& operator >> (std::ostream& s);
420  void clear();
421  };
422 
423 
429  {
430  public:
435 
436  std::ostream& operator >> (std::ostream& s);
437  };
438 
439 
446  {
447  public:
448 
455  //<saveframe_id, atom_id_in_nmr_atom_data_set>
456  typedef std::pair<Position, Position> BMRBIndex;
457  typedef std::map<Atom const* , BMRBIndex> BALLToBMRBMapping;
458  typedef std::map<const NMRAtomData*, Atom const*> BMRBToBALLMapping;
459  //TODO: Dont use pointer but something more sophisticated!
460 
462 
467 
474  BALLToBMRBMapper(Chain const& chain, const NMRStarFile& nmr_data, const String& chemical_unit);
475 
477  virtual ~BALLToBMRBMapper() {}
478 
480 
483 
485  const Chain* getChain() const {return chain_;}
486 
488  void setChain(Chain const& chain) { chain_ = &chain;
489  num_mismatches_ = -1;
490  num_gaps_ = -1;}
491 
493  void setNMRStarFile(NMRStarFile const& nmrfile) {nmr_data_ = &nmrfile;
494  num_mismatches_ = -1;
495  num_gaps_ = -1;}
496 
498  const NMRStarFile* getNMRStarFile() const {return nmr_data_;}
499 
501  void setNMRAtomDataSet(NMRAtomDataSet const& nmr_atom_data_set){nmr_atom_data_set_= &nmr_atom_data_set;}
502 
504  bool setNMRAtomDataSetByName(String const& chemical_unit_name);
505 
506  // Get the NMRAtomDataSet
507  const NMRAtomDataSet* getNMRAtomDataSet() const{return nmr_atom_data_set_;}
508 
510  BALLToBMRBMapping& getBALLToBMRBMapping() {return ball_to_bmrb_map_;}
511 
513  const BALLToBMRBMapping& getBALLToBMRBMapping() const {return ball_to_bmrb_map_;}
514 
516  BMRBToBALLMapping& getBMRBToBALLMapping() {return bmrb_to_ball_map_;}
517 
519  const BMRBToBALLMapping& getBMRBToBALLMapping() const {return bmrb_to_ball_map_;}
520 
522  int getNumberOfMismatches(){return num_mismatches_;}
523 
525  int getNumberOfGaps(){return num_gaps_;}
526 
528  bool isMapped(const NMRAtomData& nmr_atom) const;
529 
535  const Atom* getBALLAtom(const NMRAtomData& nmr_atom) const;
536 
541  bool isMapped(Atom const* atom) const;
542 
544  BMRBIndex operator () (const Atom* atom);
545 
552  bool createTrivialMapping();
553 
563  bool createMapping(const String& aligned_ball_sequence,
564  const String& aligned_nmrstar_sequence);
565 
568  void clear();
569 
571 
572  protected:
573 
575 
579 
582 
585 
586  // NOTE: do *not* attempt to delete these pointers!
587  const Chain* chain_;
593  bool valid_;
595 
596  private:
597  const Atom* findNMRAtom_(const NMRAtomData& atom) const;
598 
599  };
600 
602 
605 
608  NMRStarFile();
609 
614  NMRStarFile(const String& file_name, File::OpenMode open_mode = std::ios::in);
615 
617  ~NMRStarFile();
619 
620 
624 
628  bool read();
629 
630  /* Read an NMRStarFile and assign the shifts to the
631  given AtomContainer using a trivial standard mapping.
632  If the AtomContainer is a system, the first chain in chosen.
633 
634  @param ac AtomContainer to which the NMRStarfile's shift should be assigned.
635  @return bool - <tt>true</tt> if reading the file was successful
636  */
637  //TODO to be able to use this function, further functions getMapping() and assign() are needed.
638  bool read(AtomContainer& ac);
639 
646  bool assignShifts(BALLToBMRBMapper& ball_to_bmrb_mapping);
647 
659  bool assignShifts(AtomContainer& ac,
660  const String& chemical_unit,
661  const String& aligned_ball_sequence,
662  const String& aligned_nmrstar_sequence);
663 
666  Size getNumberOfAtoms() const;
667 
670  Size getNumberOfShiftsAssigned() const {return number_of_assigned_shifts_;};
671 
674  const std::vector<NMRAtomDataSet>& getNMRData() const;
675 
678  const EntryInformation& getEntryInformation() const {return entry_information_;};
679 
682  const MolecularSystem& getMolecularInformation() const {return molecular_system_;};
683 
686  MolecularSystem& getMolecularInformation() {return molecular_system_;};
687 
688 
691  const MolecularSystem::ChemicalUnit& getChemicalUnitByLabel(String const& label) const;
692 
695  MolecularSystem::ChemicalUnit& getChemicalUnitByLabel(String const& label);
696 
697 
700  bool hasSampleCondition(String name);
701 
704  bool hasSampleCondition(String name) const;
705 
708  SampleCondition& getSampleConditionByName(String name);
709 
712  const SampleCondition& getSampleConditionByName(String name) const;
713 
715  SampleCondition& getSampleCondition(Position i) {return sample_conditions_[i];};
716 
718  const SampleCondition& getSampleCondition(Position i) const {return sample_conditions_[i];};
719 
721  Size getNumberOfSampleConditions() const {return sample_conditions_.size();};
722 
724  const std::vector<SampleCondition>& getSampleConditions() const {return sample_conditions_;};
725 
727  std::vector<SampleCondition>& getSampleConditions() {return sample_conditions_;};
728 
729  // addSampleCondition TODO!!
730 
732  std::vector<Sample> getSamples() const {return samples_;};
733  //const std::vector<Sample>& getSamples() const {return samples_;};
734 
736  Size getNumberOfSamples() const {return samples_.size();};
737 
739  bool hasSample(String label) const;
740 
744  Sample getSample(Position i) const;
745 
749  Sample getSample(String label) const;
750 
752  std::vector<ShiftReferenceSet>& getShiftReferenceSets() {return shift_references_;};
754  const std::vector<ShiftReferenceSet>& getShiftReferenceSets() const {return shift_references_;};
755 
757  Size getNumberOfShiftReferenceSets() const {return shift_references_.size();};
758 
760  bool hasShiftReferenceSet(String name);
761 
763  ShiftReferenceSet& getShiftReferenceSet(Position i) {return shift_references_[i];};
765  const ShiftReferenceSet& getShiftReferenceSet(Position i) const {return shift_references_[i];};
766 
768  const ShiftReferenceSet& getShiftReferenceSetByName(String name) const;
770  ShiftReferenceSet& getShiftReferenceSetByName(String name);
771 
772 
774  std::vector<NMRSpectrometer>& getNMRSpectrometers() {return nmr_spectrometers_;};
776  const std::vector<NMRSpectrometer>& getNMRSpectrometers() const {return nmr_spectrometers_;};
777 
779  Size getNumberOfNMRSpectrometers() const {return nmr_spectrometers_.size();};
780 
782  NMRSpectrometer& getNMRSpectrometer(Position i);
784  const NMRSpectrometer& getNMRSpectrometer(Position i) const;
785 
787  NMRSpectrometer& getNMRSpectrometerByName(String name);
789  const NMRSpectrometer& getNMRSpectrometerByName(String name) const;
790 
792  String getNMRSpectrometerManufacturer(Position i) const;
793 
795  float getNMRSpectrometerFieldStrength(Position i) const;
796 
797 
801  NMRStarFile::MonomericPolymer& getMonomericPolymer(Position i);
802 
806  const NMRStarFile::MonomericPolymer& getMonomericPolymer(Position i) const;
807 
811  NMRStarFile::MonomericPolymer& getMonomericPolymer(const String& name);
812 
816  const NMRStarFile::MonomericPolymer& getMonomericPolymer(const String& name) const;
817 
819  Size getNumberOfMonomericPolymers() const {return monomeric_polymers_.size();};
820 
822  vector<MonomericPolymer> getMonomericPolymers() const {return monomeric_polymers_;};
823 
825  bool hasMonomericPolymer(String name) const;
826 
832  bool isMonomericPolymer(String chemical_unit_label);
833 
837  //TODO: Store changes/additions as Saveframes also in CIFFile
838  void addMonomericPolymer(MonomericPolymer mp);
839 
840 
849  String getResidueSequence(Position i=0) const;
850 
852  bool hasHshifts() const {return has_H_shifts_;};
853 
855  bool hasCshifts() const {return has_C_shifts_;};
856 
858  bool hasNshifts() const {return has_N_shifts_;};
859 
861 
862 
866 
870  bool operator == (const NMRStarFile& f) const;
871 
875  bool operator != (const NMRStarFile& f) const;
876 
879  void clear();
880 
882 
883  private:
884 
885  /*_ @name NMRStar file specific Help-Methods
886  */
887  //_@{
888 
890  void readEntryInformation_();
891 
893  void readMolSystem_();
894 
896  void readMonomericPolymers_();
897 
899  void readSampleConditions_();
900 
902  void readShiftReferences_();
903 
905  void readShifts_();
906 
908  void readSamples_();
909 
911  void readNMRSpectrometer_();
912 
914  void findDependiencies_();
915 
917  void setSpecialCharacters_(String characters);
918 
920  bool isValidSingleValue_(String value);
921 
923  float valueToFloat_(String value);
924 
926  int valueToInt_(String value);
932  bool assignShifts_(BALLToBMRBMapper& pdb_to_bmrb_mapping);
933 
934  //_@}
935  /*_ @name NMRStar file specific attributes
936  */
937  //_@{
938 
939  /*_ A flag indicating validity of this instance. A sole NMRStarFile
940  instance cannot be valid, because it does not have any information.
941  */
942  bool valid_;
943 
945  Size number_of_shift_sets_;
946 
948  Size number_of_assigned_shifts_;
949 
951  EntryInformation entry_information_;
952 
954  MolecularSystem molecular_system_;
955 
957  std::vector<NMRAtomDataSet> atom_data_sets_;
958 
960  std::vector<SampleCondition> sample_conditions_;
961 
963  std::vector<Sample> samples_;
964 
966  std::vector<ShiftReferenceSet> shift_references_;
967 
969  std::vector<NMRSpectrometer> nmr_spectrometers_;
970 
972  vector<MonomericPolymer> monomeric_polymers_;
973 
975  bool has_H_shifts_;
976  bool has_C_shifts_;
977  bool has_N_shifts_;
978 
979  // a dummy saveframe
980  SaveFrame dummy_saveframe_;
981 
982  // a dummy sample condition
983  SampleCondition dummy_sample_condition_;
984 
985  // a dummy sample
986  Sample dummy_sample_;
987 
988  // a dummy shift reference set
989  ShiftReferenceSet dummy_shift_reference_set_;
990 
991  // a dummy nmr spectrometer
992  NMRSpectrometer dummy_NMR_spectrometer_;
993 
994  // a dummy nmr spectrometer
995  MonomericPolymer dummy_monomeric_polymer_;
996 
998  String special_characters_;
999  //_@}
1000  };
1001 
1003 } // Namespace BALL
1004 
1005 #endif // BALL_FORMAT_NMRSTARFILE_H
const NMRAtomDataSet * nmr_atom_data_set_
Definition: NMRStarFile.h:589
void setChain(Chain const &chain)
Set the chain.
Definition: NMRStarFile.h:488
static const int INT_VALUE_NA
Definition: NMRStarFile.h:120
StringHashMap< float > errors
Definition: NMRStarFile.h:148
SampleCondition & getSampleCondition(Position i)
Get the i-th SampleCondition.
Definition: NMRStarFile.h:715
Peptides::NameConverter name_converter_
Definition: NMRStarFile.h:574
std::map< Atom const *, BMRBIndex > BALLToBMRBMapping
Definition: NMRStarFile.h:457
StringHashMap< String > residues_by_index
Definition: NMRStarFile.h:349
std::vector< ShiftReferenceElement > elements
Definition: NMRStarFile.h:229
BMRBToBALLMapping bmrb_to_ball_map_
map NMR atom data to BALL atoms
Definition: NMRStarFile.h:584
int getNumberOfGaps()
Return the number of mismatches in the current mapping.
Definition: NMRStarFile.h:525
bool hasCshifts() const
Check, whether this NMRFile provides carbon shifts.
Definition: NMRStarFile.h:855
BMRBToBALLMapping & getBMRBToBALLMapping()
Return the mapping.
Definition: NMRStarFile.h:516
Size getNumberOfShiftReferenceSets() const
Get the number of shift reference sets.
Definition: NMRStarFile.h:757
ShiftReferenceSet & getShiftReferenceSet(Position i)
Get the i-th shift reference set.
Definition: NMRStarFile.h:763
const std::vector< SampleCondition > & getSampleConditions() const
Get the sample conditions.
Definition: NMRStarFile.h:724
vector< RelatedDB > related_database_entries
Definition: NMRStarFile.h:415
std::vector< NMRSpectrometer > & getNMRSpectrometers()
Get the spectrometers.
Definition: NMRStarFile.h:774
const NMRAtomDataSet * getNMRAtomDataSet() const
Definition: NMRStarFile.h:507
std::istream & operator>>(std::istream &is, TRegularData1D< ValueType > &grid)
Input operator.
BALLToBMRBMapping ball_to_bmrb_map_
map BALL atoms to NMR atom data
Definition: NMRStarFile.h:581
void setNMRAtomDataSet(NMRAtomDataSet const &nmr_atom_data_set)
Set the NMRAtomDataSet.
Definition: NMRStarFile.h:501
std::vector< SampleCondition > & getSampleConditions()
Get the sample conditions.
Definition: NMRStarFile.h:727
std::vector< ShiftReferenceSet > & getShiftReferenceSets()
Get the shift reference sets.
Definition: NMRStarFile.h:752
vector< Component > components
Definition: NMRStarFile.h:188
Size getNumberOfSampleConditions() const
Get the number of sample conditions.
Definition: NMRStarFile.h:721
static const float FLOAT_VALUE_NA
Definition: NMRStarFile.h:119
Size getNumberOfSamples() const
Get the number of samples.
Definition: NMRStarFile.h:736
bool hasNshifts() const
Check, whether this NMRFile provides nitrogen shifts.
Definition: NMRStarFile.h:858
int getNumberOfMismatches()
Return the number of mismatches in the current mapping.
Definition: NMRStarFile.h:522
const BALLToBMRBMapping & getBALLToBMRBMapping() const
Return the mapping.
Definition: NMRStarFile.h:513
vector< HomologDB > homolog_database_entries
Definition: NMRStarFile.h:350
std::ios::openmode OpenMode
Definition: file.h:168
ChemicalUnit const & getChemicalUnit(Position i) const
Definition: NMRStarFile.h:399
std::map< const NMRAtomData *, Atom const * > BMRBToBALLMapping
Definition: NMRStarFile.h:458
BALLToBMRBMapping & getBALLToBMRBMapping()
Return the mapping.
Definition: NMRStarFile.h:510
vector< MonomericPolymer > getMonomericPolymers() const
Get all Monomeric Polymers.
Definition: NMRStarFile.h:822
Size getNumberOfShiftsAssigned() const
Definition: NMRStarFile.h:670
vector< ChemicalUnit > chemical_units
Definition: NMRStarFile.h:407
const std::vector< ShiftReferenceSet > & getShiftReferenceSets() const
Get the shift reference sets.
Definition: NMRStarFile.h:754
BALL_EXPORT bool operator!=(const String &s1, const String &s2)
ChemicalUnit & getChemicalUnit(Position i)
Definition: NMRStarFile.h:400
This class provides methods for reading and assigning chemical shifts.
Definition: NMRStarFile.h:113
StringHashMap< String > units
Definition: NMRStarFile.h:149
This class provides conversion of atom names between naming schemata.
Definition: peptides.h:150
std::vector< String > samples
Definition: NMRStarFile.h:278
std::pair< Position, Position > BMRBIndex
Definition: NMRStarFile.h:456
std::vector< NMRAtomData > atom_data
Definition: NMRStarFile.h:275
const BMRBToBALLMapping & getBMRBToBALLMapping() const
Return the mapping.
Definition: NMRStarFile.h:519
BALL_EXPORT bool operator==(const String &s1, const String &s2)
void setNMRStarFile(NMRStarFile const &nmrfile)
Set the NMRStar file.
Definition: NMRStarFile.h:493
const Chain * getChain() const
Get the chain.
Definition: NMRStarFile.h:485
const EntryInformation & getEntryInformation() const
Definition: NMRStarFile.h:678
std::vector< Sample > getSamples() const
Get the samples.
Definition: NMRStarFile.h:732
Size getNumberOfMonomericPolymers() const
Get the number of monomeric polymers in the file.
Definition: NMRStarFile.h:819
StringHashMap< float > values
Definition: NMRStarFile.h:147
Database with homolog entries.
Definition: NMRStarFile.h:316
float system_molecular_weight
The systems molecular weigth in dalton.
Definition: NMRStarFile.h:413
const NMRStarFile * getNMRStarFile() const
Get the NMRStar file.
Definition: NMRStarFile.h:498
virtual ~BALLToBMRBMapper()
Destructor.
Definition: NMRStarFile.h:477
bool hasHshifts() const
Check, whether this NMRFile provides hydrogen shifts.
Definition: NMRStarFile.h:852
const std::vector< NMRSpectrometer > & getNMRSpectrometers() const
Get the spectrometers.
Definition: NMRStarFile.h:776
const SampleCondition & getSampleCondition(Position i) const
Get the i-th SampleCondition.
Definition: NMRStarFile.h:718
#define BALL_EXPORT
Definition: COMMON/global.h:50
static const Position POSITION_VALUE_NA
Definition: NMRStarFile.h:122
const ShiftReferenceSet & getShiftReferenceSet(Position i) const
Get the i-th shift reference set.
Definition: NMRStarFile.h:765
const MolecularSystem & getMolecularInformation() const
Definition: NMRStarFile.h:682
Size getNumberOfNMRSpectrometers() const
Get the number of nmr spectrometers.
Definition: NMRStarFile.h:779
MolecularSystem & getMolecularInformation()
Definition: NMRStarFile.h:686