summaryrefslogtreecommitdiff
path: root/mmdb2/mmdb_symop.h
blob: f5e7af0ace6920f5be96b44274af734d579c7ed3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
//  $Id: mmdb_symop.h $
//  =================================================================
//
//   CCP4 Coordinate Library: support of coordinate-related
//   functionality in protein crystallography applications.
//
//   Copyright (C) Eugene Krissinel 2000-2013.
//
//    This library is free software: you can redistribute it and/or
//    modify it under the terms of the GNU Lesser General Public
//    License version 3, modified in accordance with the provisions
//    of the license to address the requirements of UK law.
//
//    You should have received a copy of the modified GNU Lesser
//    General Public License along with this library. If not, copies
//    may be downloaded from http://www.ccp4.ac.uk/ccp4license.php
//
//    This program is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//    GNU Lesser General Public License for more details.
//
//  =================================================================
//
//    12.09.13   <--  Date of Last Modification.
//                   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//  -----------------------------------------------------------------
//
//  **** Module  :   MMDB_SymOp <interface>
//       ~~~~~~~~~
//  **** Project :   MacroMolecular Data Base (MMDB)
//       ~~~~~~~~~
//
//  **** Classes :   mmdb::SymOp  ( symmetry operators )
//       ~~~~~~~~~   mmdb::SymOps ( container of symmetry operators )
//
//   (C) E. Krissinel 2000-2013
//
//  =================================================================
//

#ifndef __MMDB_SymOp__
#define __MMDB_SymOp__

#include "mmdb_io_stream.h"
#include "mmdb_defs.h"

namespace mmdb  {

  //  ====================  SymOp  ========================

  DefineClass(SymOp);
  DefineStreamFunctions(SymOp);

  class SymOp : public io::Stream  {

    public :

      SymOp ();
      SymOp ( io::RPStream Object );
      ~SymOp();

      int  SetSymOp  ( cpstr XYZOperation );
      pstr GetSymOp  ();

      void Transform ( realtype & x, realtype & y, realtype & z );

      void GetTMatrix ( mat44 & TMatrix );  // copies T to TMatrix
      void SetTMatrix ( mat44 & TMatrix );  // copies TMatrix to T

      bool CompileOpTitle ( pstr S );  // makes XYZOp from matrix T
      bool CompileOpTitle ( pstr S, mat44 symMat, bool compare );
      void Print          ();          // prints operation and matrix

      void Copy  ( PSymOp symOp );

      void write ( io::RFile f );
      void read  ( io::RFile f );

    protected :
      pstr  XYZOp;
      mat44 T;

      void InitSymOp    ();
      void FreeMemory   ();
      int  GetOperation ( int n );

  };


  //  ====================  SymOps  ========================

  enum SYMOP_RC  {
    SYMOP_Ok                =  0,
    SYMOP_NoLibFile         = -1,
    SYMOP_UnknownSpaceGroup = -2,
    SYMOP_NoSymOps          = -3,
    SYMOP_WrongSyntax       = -4,
    SYMOP_NotAnOperation    = -5,
    SYMOP_ZeroDenominator   = -6
  };

  DefineClass(SymOps);
  DefineStreamFunctions(SymOps);

  class SymOps : public io::Stream  {

    public :

      SymOps ();
      SymOps ( io::RPStream Object );
      ~SymOps();

      virtual void FreeMemory();

      int  SetGroupSymopLib ( cpstr SpaceGroup,
                              cpstr symop_lib=NULL );
        // Space Group is taken from symop.lib. Return Code:
        // SYMOP_Ok <=> success

      int  SetGroup ( cpstr SpaceGroup,
                      cpstr syminfo_lib=NULL );
        // Space Group is taken from syminfo.lib. Return Code:
        // SYMOP_Ok <=> success

      void Reset           ();        // removes all symmetry operations
      virtual int AddSymOp ( cpstr XYZOperation ); // adds symmetry
                                                   // operation
      void PutGroupName    ( cpstr SpGroupName  );

      //  GetNofSymOps()  returns Nops -- the number of sym. operations
      int  GetNofSymOps ();
      pstr GetSymOp     ( int Nop );

      //  Transform(..) transforms the coordinates according to the
      // symmetry operation Nop. The return code is non-zero if
      // Nop is a wrong operation number (must range from 0 to Nops-1).
      int  Transform ( realtype & x, realtype & y, realtype & z,
                       int Nop );

      //  GetTMatrix(..) returns the coordinate transformation matrix
      // for the symmetry operation Nop. The return code is non-zero if
      // Nop is a wrong operation number (must range from 0 to Nops-1).
      int  GetTMatrix ( mat44 & TMatrix, int Nop );

      void Print ();

      virtual void Copy ( PSymOps symOps );

      void write ( io::RFile f );
      void read  ( io::RFile f );

    protected :

      pstr    SpGroup;
      int     Nops;
      PPSymOp symOp;

      void InitSymOps();

  };

}  // namespace mmdb

// extern void TestSymOps();

#endif