/* * Project: MoleCuilder * Description: creates and alters molecular systems * Copyright (C) 2010 University of Bonn. All rights reserved. * Please see the LICENSE file or "Copyright notice" in builder.cpp for details. */ /* * ForceMatrix.cpp * * Created on: Sep 15, 2011 * Author: heber */ // include config.h #ifdef HAVE_CONFIG_H #include #endif #include "CodePatterns/MemDebug.hpp" #include #include #include "CodePatterns/Log.hpp" #include "KeySetsContainer.hpp" #include "Fragmentation/helpers.hpp" #include "Helpers/defs.hpp" #include "Helpers/helpers.hpp" #include "ForceMatrix.hpp" /** Parsing force Indices of each fragment * \param *name directory with \a ForcesFile * \return parsing successful */ bool ForceMatrix::ParseIndices(const char *name) { ifstream input; char *FragmentNumber = NULL; char filename[1023]; stringstream line; LOG(0, "Parsing force indices for " << MatrixCounter << " matrices."); Indices.resize(MatrixCounter + 1); line << name << FRAGMENTPREFIX << FORCESFILE; input.open(line.str().c_str(), ios::in); //LOG(0, "Opening " << line.str() << " ... " << input); if (input.fail()) { LOG(0, endl << "ForceMatrix::ParseIndices: Unable to open " << line.str() << ", is the directory correct?"); return false; } for (int i=0;(i> Indices[i][j]; //output << " " << Indices[i][j]; } //LOG(0, output.str()); } Indices[MatrixCounter].resize(RowCounter[MatrixCounter]); for(int j=RowCounter[MatrixCounter];j--;) { Indices[MatrixCounter][j] = j; } input.close(); return true; }; /** Sums the forces and puts into last element of \a ForceMatrix::Matrix. * \param Matrix MatrixContainer with matrices (LevelCounter by *ColumnCounter) with all the energies. * \param KeySets KeySetContainer with bond Order and association mapping of each fragment to an order * \param Order bond order * \param sign +1 or -1 * \return true if summing was successful */ bool ForceMatrix::SumSubForces(class ForceMatrix &Fragments, class KeySetsContainer &KeySets, int Order, double sign) { int FragmentNr; // sum forces for(int i=0;i RowCounter[MatrixCounter]) { ELOG(0, "Current force index " << j << " is greater than " << RowCounter[MatrixCounter] << "!"); performCriticalExit(); return false; } if (j != -1) { //if (j == 0) LOG(0, "Summing onto ion 0, type 0 from fragment " << FragmentNr << ", ion " << l << "."); for(int k=2;k> nr; //LOG(0, "Current index: " << getNr() << "."); if (nr > RowCounter[MatrixCounter]) RowCounter[MatrixCounter] = nr; } } RowCounter[MatrixCounter]++; // Nr start at 0, count starts at 1 input.close(); ColumnCounter[MatrixCounter] = 0; for(int j=0; j < MatrixCounter;j++) { // (energy matrix might be bigger than number of atoms in terms of rows) if (ColumnCounter[j] > ColumnCounter[MatrixCounter]) // take maximum of all for last matrix ColumnCounter[MatrixCounter] = ColumnCounter[j]; } // allocate last plus one matrix if (Matrix[MatrixCounter].size() <= RowCounter[MatrixCounter] + 2) Matrix[MatrixCounter].resize(RowCounter[MatrixCounter] + 1); for(int j=0;j<=RowCounter[MatrixCounter];j++) if (Matrix[MatrixCounter][j].size() <= ColumnCounter[MatrixCounter]+1) Matrix[MatrixCounter][j].resize(ColumnCounter[MatrixCounter]); // try independently to parse global forcesuffix file if present strncpy(filename, name, 1023); strncat(filename, prefix, 1023-strlen(filename)); strncat(filename, suffix.c_str(), 1023-strlen(filename)); std::ifstream input(filename); ParseMatrix(input, skiplines, skipcolumns, MatrixCounter); input.close(); } return status; };