[bcf653] | 1 | /*
|
---|
| 2 | * Project: MoleCuilder
|
---|
| 3 | * Description: creates and alters molecular systems
|
---|
| 4 | * Copyright (C) 2010 University of Bonn. All rights reserved.
|
---|
| 5 | * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
|
---|
| 6 | */
|
---|
| 7 |
|
---|
[b70721] | 8 | /*
|
---|
| 9 | * bondgraph.cpp
|
---|
| 10 | *
|
---|
| 11 | * Created on: Oct 29, 2009
|
---|
| 12 | * Author: heber
|
---|
| 13 | */
|
---|
| 14 |
|
---|
[bf3817] | 15 | // include config.h
|
---|
| 16 | #ifdef HAVE_CONFIG_H
|
---|
| 17 | #include <config.h>
|
---|
| 18 | #endif
|
---|
| 19 |
|
---|
[ad011c] | 20 | #include "CodePatterns/MemDebug.hpp"
|
---|
[112b09] | 21 |
|
---|
[b70721] | 22 | #include <iostream>
|
---|
| 23 |
|
---|
| 24 | #include "atom.hpp"
|
---|
[1cbf47] | 25 | #include "bond.hpp"
|
---|
[b70721] | 26 | #include "bondgraph.hpp"
|
---|
| 27 | #include "element.hpp"
|
---|
[ad011c] | 28 | #include "CodePatterns/Info.hpp"
|
---|
| 29 | #include "CodePatterns/Verbose.hpp"
|
---|
| 30 | #include "CodePatterns/Log.hpp"
|
---|
[b70721] | 31 | #include "molecule.hpp"
|
---|
| 32 | #include "parser.hpp"
|
---|
[ae38fb] | 33 | #include "periodentafel.hpp"
|
---|
[57f243] | 34 | #include "LinearAlgebra/Vector.hpp"
|
---|
[b70721] | 35 |
|
---|
[88b400] | 36 | const double BondGraph::BondThreshold = 0.4; //!< CSD threshold in bond check which is the width of the interval whose center is the sum of the covalent radii
|
---|
| 37 |
|
---|
[97b825] | 38 | BondGraph::BondGraph(bool IsA) :
|
---|
| 39 | BondLengthMatrix(NULL),
|
---|
| 40 | max_distance(0),
|
---|
| 41 | IsAngstroem(IsA)
|
---|
| 42 | {};
|
---|
[b70721] | 43 |
|
---|
| 44 | BondGraph::~BondGraph()
|
---|
| 45 | {
|
---|
| 46 | if (BondLengthMatrix != NULL) {
|
---|
| 47 | delete(BondLengthMatrix);
|
---|
| 48 | }
|
---|
| 49 | };
|
---|
| 50 |
|
---|
[4e855e] | 51 | bool BondGraph::LoadBondLengthTable(std::istream &input)
|
---|
[b70721] | 52 | {
|
---|
[244a84] | 53 | Info FunctionInfo(__func__);
|
---|
[b70721] | 54 | bool status = true;
|
---|
[34e0013] | 55 | MatrixContainer *TempContainer = NULL;
|
---|
[b70721] | 56 |
|
---|
| 57 | // allocate MatrixContainer
|
---|
| 58 | if (BondLengthMatrix != NULL) {
|
---|
[a67d19] | 59 | DoLog(1) && (Log() << Verbose(1) << "MatrixContainer for Bond length already present, removing." << endl);
|
---|
[b70721] | 60 | delete(BondLengthMatrix);
|
---|
| 61 | }
|
---|
[34e0013] | 62 | TempContainer = new MatrixContainer;
|
---|
[b70721] | 63 |
|
---|
| 64 | // parse in matrix
|
---|
[4e855e] | 65 | if ((input.good()) && (status = TempContainer->ParseMatrix(input, 0, 1, 0))) {
|
---|
[a67d19] | 66 | DoLog(1) && (Log() << Verbose(1) << "Parsing bond length matrix successful." << endl);
|
---|
[244a84] | 67 | } else {
|
---|
[58ed4a] | 68 | DoeLog(1) && (eLog()<< Verbose(1) << "Parsing bond length matrix failed." << endl);
|
---|
[4e855e] | 69 | status = false;
|
---|
[244a84] | 70 | }
|
---|
[b70721] | 71 |
|
---|
| 72 | // find greatest distance
|
---|
| 73 | max_distance=0;
|
---|
[34e0013] | 74 | if (status) {
|
---|
| 75 | for(int i=0;i<TempContainer->RowCounter[0];i++)
|
---|
| 76 | for(int j=i;j<TempContainer->ColumnCounter[0];j++)
|
---|
| 77 | if (TempContainer->Matrix[0][i][j] > max_distance)
|
---|
| 78 | max_distance = TempContainer->Matrix[0][i][j];
|
---|
| 79 | }
|
---|
[b5cf6c] | 80 | max_distance += BondThreshold;
|
---|
[b70721] | 81 |
|
---|
[34e0013] | 82 | if (status) // set to not NULL only if matrix was parsed
|
---|
| 83 | BondLengthMatrix = TempContainer;
|
---|
| 84 | else {
|
---|
| 85 | BondLengthMatrix = NULL;
|
---|
| 86 | delete(TempContainer);
|
---|
| 87 | }
|
---|
[b70721] | 88 | return status;
|
---|
| 89 | };
|
---|
| 90 |
|
---|
[715b67] | 91 | bool BondGraph::CreateAdjacencyForMolecule(molecule * const mol)
|
---|
[b70721] | 92 | {
|
---|
[1cbf47] | 93 | Info FunctionInfo(__func__);
|
---|
[bd6bfa] | 94 | bool status = true;
|
---|
[b70721] | 95 |
|
---|
[9879f6] | 96 | if (mol->empty()) // only construct if molecule is not empty
|
---|
[34e0013] | 97 | return false;
|
---|
| 98 |
|
---|
[72d90e] | 99 | SetMaxDistanceToMaxOfCovalentRadii(mol);
|
---|
| 100 | mol->CreateAdjacencyList(max_distance, IsAngstroem, &BondGraph::getMinMaxDistance, this);
|
---|
[b70721] | 101 |
|
---|
| 102 | return status;
|
---|
| 103 | };
|
---|
| 104 |
|
---|
| 105 | double BondGraph::GetBondLength(int firstZ, int secondZ)
|
---|
| 106 | {
|
---|
[4e855e] | 107 | std::cout << "Request for length between " << firstZ << " and " << secondZ << ": ";
|
---|
| 108 | if (BondLengthMatrix == NULL) {
|
---|
| 109 | std::cout << "-1." << std::endl;
|
---|
[34e0013] | 110 | return( -1. );
|
---|
[4e855e] | 111 | } else {
|
---|
| 112 | std::cout << BondLengthMatrix->Matrix[0][firstZ][secondZ] << std::endl;
|
---|
[34e0013] | 113 | return (BondLengthMatrix->Matrix[0][firstZ][secondZ]);
|
---|
[4e855e] | 114 | }
|
---|
[b70721] | 115 | };
|
---|
| 116 |
|
---|
[e138de] | 117 | double BondGraph::SetMaxDistanceToMaxOfCovalentRadii(const molecule * const mol)
|
---|
[ae38fb] | 118 | {
|
---|
[1cbf47] | 119 | Info FunctionInfo(__func__);
|
---|
[ae38fb] | 120 | max_distance = 0.;
|
---|
| 121 |
|
---|
[9879f6] | 122 | for (molecule::const_iterator iter = mol->begin(); iter != mol->end(); ++iter) {
|
---|
[83f176] | 123 | if ((*iter)->getType()->getCovalentRadius() > max_distance)
|
---|
| 124 | max_distance = (*iter)->getType()->getCovalentRadius();
|
---|
[ae38fb] | 125 | }
|
---|
| 126 | max_distance *= 2.;
|
---|
[b5cf6c] | 127 | max_distance += BondThreshold;
|
---|
[ae38fb] | 128 |
|
---|
| 129 | return max_distance;
|
---|
| 130 | };
|
---|
| 131 |
|
---|
[af2c424] | 132 | double BondGraph::getMaxDistance() const
|
---|
| 133 | {
|
---|
| 134 | return max_distance;
|
---|
| 135 | }
|
---|
| 136 |
|
---|
| 137 |
|
---|
[b70721] | 138 | void BondGraph::CovalentMinMaxDistance(BondedParticle * const Walker, BondedParticle * const OtherWalker, double &MinDistance, double &MaxDistance, bool IsAngstroem)
|
---|
| 139 | {
|
---|
[83f176] | 140 | MinDistance = OtherWalker->getType()->getCovalentRadius() + Walker->getType()->getCovalentRadius();
|
---|
[b70721] | 141 | MinDistance *= (IsAngstroem) ? 1. : 1. / AtomicLengthToAngstroem;
|
---|
[88b400] | 142 | MaxDistance = MinDistance + BondThreshold;
|
---|
| 143 | MinDistance -= BondThreshold;
|
---|
[b70721] | 144 | };
|
---|
| 145 |
|
---|
| 146 | void BondGraph::BondLengthMatrixMinMaxDistance(BondedParticle * const Walker, BondedParticle * const OtherWalker, double &MinDistance, double &MaxDistance, bool IsAngstroem)
|
---|
[72d90e] | 147 | {
|
---|
| 148 | ASSERT(BondLengthMatrix != NULL,
|
---|
| 149 | "BondGraph::BondLengthMatrixMinMaxDistance() called without NULL BondLengthMatrix.");
|
---|
| 150 | MinDistance = GetBondLength(Walker->getType()->getAtomicNumber()-1, OtherWalker->getType()->getAtomicNumber()-1);
|
---|
| 151 | MinDistance *= (IsAngstroem) ? 1. : 1. / AtomicLengthToAngstroem;
|
---|
| 152 | MaxDistance = MinDistance + BondThreshold;
|
---|
| 153 | MinDistance -= BondThreshold;
|
---|
| 154 | };
|
---|
| 155 |
|
---|
| 156 | void BondGraph::getMinMaxDistance(BondedParticle * const Walker, BondedParticle * const OtherWalker, double &MinDistance, double &MaxDistance, bool IsAngstroem)
|
---|
[b70721] | 157 | {
|
---|
[34e0013] | 158 | if (BondLengthMatrix == NULL) {// safety measure if no matrix has been parsed yet
|
---|
[72d90e] | 159 | LOG(2, "INFO: Using Covalent radii criterion for [min,max] distances.");
|
---|
[b21a64] | 160 | CovalentMinMaxDistance(Walker, OtherWalker, MinDistance, MaxDistance, IsAngstroem);
|
---|
| 161 | } else {
|
---|
[72d90e] | 162 | LOG(2, "INFO: Using Covalent radii criterion for [min,max] distances.");
|
---|
| 163 | BondLengthMatrixMinMaxDistance(Walker, OtherWalker, MinDistance, MaxDistance, IsAngstroem);
|
---|
[b21a64] | 164 | }
|
---|
[72d90e] | 165 | }
|
---|