File: mmdb_bondmngr.cpp

package info (click to toggle)
mmdb 2.0.5-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster
  • size: 3,736 kB
  • sloc: cpp: 45,698; sh: 11,463; makefile: 35
file content (121 lines) | stat: -rw-r--r-- 3,522 bytes parent folder | download | duplicates (2)
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
//  $Id: mmdb_bondmngr.cpp $
//  =================================================================
//
//   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.
//
//  =================================================================
//
//    15.09.13   <--  Date of Last Modification.
//                   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//  -----------------------------------------------------------------
//
//  **** Module  :  mmdb_bondmngr <implementation>
//       ~~~~~~~~~
//       Project :  MacroMolecular Data Base (MMDB)
//       ~~~~~~~~~
//  **** Classes :  mmdb::BondManager ( MMDB bonds maker )
//       ~~~~~~~~~
//
//  (C) E. Krissinel 2000-2013
//
//  =================================================================
//


#include <string.h>

#include "mmdb_bondmngr.h"
#include "mmdb_math_graph.h"

namespace mmdb  {

  //  =====================   BondManager   =====================

  BondManager::BondManager() : SelManager()  {
  }

  BondManager::BondManager ( io::RPStream Object )
             : SelManager(Object)  {
  }

  BondManager::~BondManager()  {}

  void  BondManager::MakeBonds ( bool calc_only )  {
  UNUSED_ARGUMENT(calc_only);
  PModel         mdl;
  PChain         chain;
  PResidue       res;
  math::Graph    graph;
  math::PPVertex V;
  math::PPEdge   E;
  int            i, im,ic,ir, nV,nE, k1,k2;

    RemoveBonds();

    for (im=0;im<nModels;im++)  {
      mdl = model[im];
      if (mdl)
        for (ic=0;ic<mdl->nChains;ic++)  {
          chain = mdl->chain[ic];
          if (chain)
            for (ir=0;ir<chain->nResidues;ir++)  {
              res = chain->residue[ir];
              if (res)  {
                graph.MakeGraph   ( res,NULL );
                graph.GetVertices ( V,nV );
                graph.GetEdges    ( E,nE );
                for (i=0;i<nE;i++)  {
                  k1 = V[E[i]->GetVertex1()-1]->GetUserID();
                  k2 = V[E[i]->GetVertex2()-1]->GetUserID();
                  res->atom[k1]->AddBond ( res->atom[k2],E[i]->GetType() );
                  res->atom[k2]->AddBond ( res->atom[k1],E[i]->GetType() );
                }
              }
            }
        }
    }

  }

  void  BondManager::RemoveBonds()  {
  int i;
    for (i=0;i<nAtoms;i++)
      if (atom[i])
        atom[i]->FreeBonds();
  }

  //  -------------------  Stream functions  ----------------------

  void  BondManager::write ( io::RFile f )  {
  byte Version=1;
    f.WriteByte ( &Version );
    SelManager::write ( f );
  }

  void  BondManager::read ( io::RFile f )  {
  byte Version;
    f.ReadByte ( &Version );
    SelManager::read ( f );
  }


  MakeStreamFunctions(BondManager)

}  // namespace mmdb