1 // $Id: ssm_align.h $
2 //  =================================================================
3 //
4 //   CCP4 SSM Library: Protein structure superposition based on
5 //   SSM algorithm: E. Krissinel & K. Henrick (2004) Acta Cryst. D60,
6 //   2256-2268.
7 //
8 //   Copyright (C) Eugene Krissinel 2002-2013.
9 //
10 //   This library is free software: you can redistribute it and/or
11 //   modify it under the terms of the GNU Lesser General Public
12 //   License version 3, modified in accordance with the provisions
13 //   of the license to address the requirements of UK law.
14 //
15 //   You should have received a copy of the modified GNU Lesser
16 //   General Public License along with this library. If not, copies
17 //   may be downloaded from http://www.ccp4.ac.uk/ccp4license.php
18 //
19 //   This program is distributed in the hope that it will be useful,
20 //   but WITHOUT ANY WARRANTY; without even the implied warranty of
21 //   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22 //   GNU Lesser General Public License for more details.
23 //
24 // =================================================================
25 //
26 //    03.02.14   <--  Date of Last Modification.
27 //                   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
28 //  ----------------------------------------------------------------
29 //
30 //  **** Module  :  SSM_Align <interface>
31 //       ~~~~~~~~~
32 //  **** Project :  Structure alignment in 3D
33 //       ~~~~~~~~~
34 //  **** Classes :  ssm::Align   ( Secondary Structure Matching )
35 //       ~~~~~~~~~  ssm::XAlign  ( Output alignment             )
36 //                  ssm::XTAlign ( Text output alignment        )
37 //
38 //  E. Krissinel, 2002-2014
39 //
40 // =================================================================
41 //
42 
43 #ifndef  __SSM_Align__
44 #define  __SSM_Align__
45 
46 #include "mmdb2/mmdb_manager.h"
47 
48 #include "ssm_superpose.h"
49 #include "ssm_csia.h"
50 
51 
52 //  ---------------------------  Align  ------------------------
53 
54 namespace ssm {
55 
56   DefineClass(Align);
57   DefineStreamFunctions(Align);
58 
59   class Align : public mmdb::io::Stream  {
60 
61     public :
62       mmdb::mat44    TMatrix; //!< superposition matrix to be applied to 1st structure
63       mmdb::realtype    rmsd; //!< core rmsd achieved
64       mmdb::realtype  Qscore; //!< core Q achieved
65       int            cnCheck; //!< connectivity option used
66       int        nres1,nres2; //!< number of residues in structures
67       int        nsel1,nsel2; //!< number of residues in aligned selections
68       int              nalgn; //!< number of aligned residues
69       int              ngaps; //!< number of gaps
70       int                nmd; //!< number of misdirections
71       mmdb::realtype  ncombs; //!< number of SSE combinations
72       mmdb::realtype seqIdentity; //!< sequence identity
73       int    selHndCa1,selHndCa2; //!< selection handles to used C-alphas
74       mmdb::ivector  Ca1,Ca2; //!< C-alpha correspondence vectors
75                               /// Ca1[i] corresponds to a[i], where a is
76                               /// selection identified by selHndCa1
77       mmdb::rvector    dist1; //!< optimizedd distances between the query
78                               /// and target C-alphas
79       PGraph           G1,G2; //!< retained SSE graphs
80 
81       Align ();
82       Align ( mmdb::io::RPStream Object );
83       ~Align();
84 
85       int align ( mmdb::PManager M1, mmdb::PManager M2,
86                   PRECISION     precision,
87                   CONNECTIVITY  connectivity,
88                   int selHnd1=0, int selHnd2=0 );
89 
90       int AlignSelectedMatch ( mmdb::PManager M1, mmdb::PManager M2,
91                                PRECISION     precision,
92                                CONNECTIVITY  connectivity,
93                                int selHnd1=0, int selHnd2=0,
94                                int nselect=0 );
95 
GetQvalues()96       mmdb::rvector GetQvalues () const { return pqvalues; }
GetNMatches()97       int           GetNMatches() const { return nMatches; }
98 
GetSuperpose()99       PSuperpose GetSuperpose() { return &superpose; }
100 
101       void  read  ( mmdb::io::RFile f );
102       void  write ( mmdb::io::RFile f );
103 
104     protected :
105       GraphMatch    U;
106       Superpose     superpose;
107       mmdb::rvector pqvalues;
108       int           nMatches;
109 
110       void  InitAlign ();
111       void  FreeMemory();
112       void  MapSelections  ( int & selHndCa, mmdb::PManager M,
113                              PGraph G, int selHnd,
114                              mmdb::ivector & newID );
115       void  MakeSelections ( mmdb::PManager M1, int selHnd1,
116                              mmdb::PManager M2, int selHnd2 );
117 
118   };
119 
120 
121   //  -----------------------------  XAlign --------------------------
122 
123   DefineStructure(XBlock);
124 
125   struct XBlock  {
126     int         i1,i2;  //!< the outer block boundaries
127     int       ip1,ip2;  //!< the alignment boundaries (ip1>=i1, ip2<=i2)
128     int          icol;  //!< the block "column" number
129     mmdb::realtype mc;  //!< center of "index mass"
130   };
131 
132 
133   DefineClass(XAlign);
134 
135   class XAlign  {
136 
137     public :
138       XAlign();
139       virtual ~XAlign();
140 
141       void align (
142           PGraph g1, mmdb::PPAtom Calpha1, mmdb::ivector Ca1, int nat1,
143           PGraph g2, mmdb::PPAtom Calpha2, mmdb::ivector Ca2, int nat2,
144           mmdb::rvector dist1, int & nr );
145 
GetNCols2()146       int  GetNCols2() { return nCols2; }
147 
148     protected :
149       PXBlock  XBlock1,XBlock2;
150       int      nBlock1,nBlock2;
151       int      na1,na2,nCols1,nCols2,nRows,algnLen;
152 
153       mmdb::ivector  a1,a2;
154       mmdb::PPAtom   alpha1,alpha2;
155       PGraph         sg1,sg2;
156       mmdb::rvector  d1;
157       mmdb::realtype maxdist;
158 
159       virtual void FreeMemory();
160       virtual void customInit();
161       int   makeXBlocks  ( mmdb::ivector Ca, int nat, RPXBlock xBlock,
162                            int & nBlocks );
163       void  alignXBlocks ( RXBlock B1, RXBlock B2, int & nr );
164 
165       virtual void makeRow ( mmdb::PAtom A1, int sseType1,
166                              mmdb::PAtom A2, int sseType2,
167                              mmdb::realtype dist, int rowNo, int icol,
168                              bool aligned );
169   };
170 
171 
172   //  ----------------------------  XTAlign --------------------------
173 
174   DefineStructure(XTAlign);
175 
176   struct XTAlign  {
177     mmdb::realtype hydropathy1,hydropathy2,dist;
178     mmdb::ChainID  chID1,chID2;
179     mmdb::ResName  resName1,resName2;
180     mmdb::InsCode  insCode1,insCode2;
181     int      alignKey; //!< 0: aligned, 1: not aligned, 2: NULL 1, 3: NULL 2
182     int      loopNo;
183     int      sseType1,sseType2;
184     int      seqNum1,seqNum2;
185     int      simindex;
186     void  Print ( mmdb::io::RFile f );
187   };
188 
189   DefineClass(XAlignText);
190 
191   class XAlignText : public XAlign  {
192 
193     public :
194       XAlignText ();
195       ~XAlignText();
196 
GetTextRows()197       PXTAlign GetTextRows   () { return R; }
198       void     GetAlignments ( mmdb::pstr & algn1, mmdb::pstr & algn2 );
199       void     WipeTextRows  ();
200 
201     protected :
202       PXTAlign R;
203 
204       void customFree();
205       void customInit();
206       void makeRow   ( mmdb::PAtom A1, int sseType1,
207                        mmdb::PAtom A2, int sseType2,
208                        mmdb::realtype dist, int rowNo, int icol,
209                        bool aligned );
210   };
211 
212   extern void PrintAlignTable ( mmdb::io::RFile f,
213                                 mmdb::PManager M1, mmdb::PManager M2,
214                                 PAlign SSMAlign );
215 }
216 
217 #endif
218