Pteros  2.0
Molecular modeling library for human beings!
mol_file.h
1 /*
2  *
3  * This source code is part of
4  * ******************
5  * *** Pteros ***
6  * ******************
7  * molecular modeling library
8  *
9  * Copyright (c) 2009-2013, Semen Yesylevskyy
10  *
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of Artistic License:
13  *
14  * Please note, that Artistic License is slightly more restrictive
15  * then GPL license in terms of distributing the modified versions
16  * of this software (they should be approved first).
17  * Read http://www.opensource.org/licenses/artistic-license-2.0.php
18  * for details. Such license fits scientific software better then
19  * GPL because it prevents the distribution of bugged derivatives.
20  *
21 */
22 
23 #ifndef MOL_FILE_H
24 #define MOL_FILE_H
25 
26 #include <string>
27 #include "pteros/core/system.h"
28 #include "pteros/core/selection.h"
29 
30 namespace pteros {
31 
33 enum {
34  MFC_ATOMS = 0x01, // The list of atoms and their properties
35  MFC_COORD = 0x02, // Single set of coordinates
36  MFC_TRAJ = 0x04, // Many frames
37  MFC_TOP = 0x08, // Molecular topology
38  MFC_RAND = 0x10 // Random access trajectory (for the future)
39 };
40 typedef unsigned short Mol_file_content;
41 
43 class Mol_file {
44 public:
46  static std::unique_ptr<Mol_file> recognize(std::string fname);
47 
55  static std::unique_ptr<Mol_file> open(std::string fname, char open_mode);
56 
58  virtual void open(char open_mode) = 0;
59 
60  virtual ~Mol_file();
61 
65  bool read(System* sys, Frame* frame, const Mol_file_content& what);
66 
68  void write(const Selection& sel, const Mol_file_content& what);
69 
71  virtual Mol_file_content get_content_type() const = 0;
72 
73 protected:
74  Mol_file(std::string& file_name);
75 
76  // Stores file name
77  std::string fname;
78  // Number of atoms
79  int natoms;
80  // Functions called to update System on file reading
81  // Mol_file is a friend of System and can access it's internals
82  // but derived *_file classes are not friends and need to call these functions.
83  void allocate_atoms_in_system(System& sys, int n);
84  void set_atom_in_system(System& sys, int i, Atom& at);
85  Atom& atom_in_system(System& sys, int i);
86  void append_atom_in_system(System& sys, Atom& at);
87  Force_field& ff_in_system(System& sys);
88 
89  // Method to sanity check parameters send to read and write
90  void sanity_check_read(System* sys, Frame* frame, const Mol_file_content &what) const;
91  void sanity_check_write(const Selection& sel, const Mol_file_content& what) const;
92 
94  virtual bool do_read(System* sys, Frame* frame, const Mol_file_content& what) = 0;
95 
97  virtual void do_write(const Selection& sel, const Mol_file_content& what) = 0;
98 };
99 
100 float get_mass_from_atom_name(std::string& name);
101 
102 }
103 #endif /* MOL_FILE_H */
bool read(System *sys, Frame *frame, const Mol_file_content &what)
Reads data, which are specified by what.
Definition: mol_file.cpp:47
Definition of single trajectory frame.
Definition: system.h:67
Pteros namespace.
Definition: options.cpp:32
Force field parameters of the system.
Definition: force_field.h:47
The system of atoms.
Definition: system.h:95
void write(const Selection &sel, const Mol_file_content &what)
Write data from selection specidied by what.
Definition: mol_file.cpp:52
Selection class.
Definition: atom_proxy.h:57
virtual Mol_file_content get_content_type() const =0
Reports content of this file type.
Class which represents a single atom.
Definition: atom.h:33
Generic API for reading and writing any molecule file formats.
Definition: mol_file.h:43
static std::unique_ptr< Mol_file > open(std::string fname, char open_mode)
Recognize file extension, open file for reading or writing and return a file handler.
Definition: mol_file.cpp:142
static std::unique_ptr< Mol_file > recognize(std::string fname)
Recognizes file extension and returns a file handler.
Definition: mol_file.cpp:126