source: src/Fragmentation/Homology/HomologyGraph.cpp

stable v1.7.0
Last change on this file was 999eaf, checked in by Frederik Heber <frederik.heber@…>, 5 years ago

Added EvaluateStabilityAction to estimate a molecule's stability.

  • removes every bond and checks the energies of the products against the educt equipped with enough hydrogen molecules to compensate for the cut bond times its degree.
  • outputs a CSV file with entries per bond.
  • extended HomologyGraph to allow direct use of AtomIdSet, i.e. atomic ids coming from a selection in the World or from the molecule.
  • DOCU: Added subsection on this action to section homology.
  • TEST: Added regression test case.
  • Property mode set to 100644
File size: 4.2 KB
RevLine 
[7b6b21f]1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2012 University of Bonn. All rights reserved.
[5aaa43]5 * Copyright (C) 2013 Frederik Heber. All rights reserved.
[7b6b21f]6 * Please see the COPYING file or "Copyright notice" in builder.cpp for details.
7 *
8 *
9 * This file is part of MoleCuilder.
10 *
11 * MoleCuilder is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation, either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * MoleCuilder is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with MoleCuilder. If not, see <http://www.gnu.org/licenses/>.
23 */
24
25/*
26 * HomologyGraph.cpp
27 *
28 * Created on: Sep 24, 2012
29 * Author: heber
30 */
31
32
33// include config.h
34#ifdef HAVE_CONFIG_H
35#include <config.h>
36#endif
37
[67db80]38// include headers that implement a archive in simple text format
39// otherwise BOOST_CLASS_EXPORT_IMPLEMENT has no effect
40#include <boost/archive/text_oarchive.hpp>
41#include <boost/archive/text_iarchive.hpp>
42
[9eb71b3]43//#include "CodePatterns/MemDebug.hpp"
[7b6b21f]44
45#include "HomologyGraph.hpp"
46
[54a561]47#include <iostream>
[77b350]48
49HomologyGraph::HomologyGraph(const KeySet &keyset) :
50 nodes(detail::getNodesFromKeySet(keyset)),
51 edges(detail::getEdgesFromKeySet(keyset))
52{}
53
[372c912]54HomologyGraph::HomologyGraph(const IndexSet &index) :
55 nodes(detail::getNodesFromIndexSet(index)),
56 edges(detail::getEdgesFromIndexSet(index))
57{}
58
[999eaf]59HomologyGraph::HomologyGraph(const AtomIdSet::atomIdSet &index) :
60 nodes(detail::getNodesFromAtomIds(index)),
61 edges(detail::getEdgesFromAtomIds(index))
62{}
63
[7b6b21f]64bool HomologyGraph::operator<(const HomologyGraph &graph) const
65{
66 if (nodes < graph.nodes) {
67 return true;
68 } else if (nodes > graph.nodes) {
69 return false;
70 } else {
71 if (edges < graph.edges)
72 return true;
73 else
74 return false;
75 }
76}
77
78bool HomologyGraph::operator>(const HomologyGraph &graph) const
79{
80 if (nodes > graph.nodes) {
81 return true;
82 } else if (nodes < graph.nodes) {
83 return false;
84 } else {
85 if (edges > graph.edges)
86 return true;
87 else
88 return false;
89 }
90}
91
92bool HomologyGraph::operator==(const HomologyGraph &graph) const
93{
94 if (nodes != graph.nodes) {
95 return false;
96 } else {
97 return (edges == graph.edges);
98 }
99}
100
101HomologyGraph& HomologyGraph::operator=(const HomologyGraph &graph)
102{
103 // self-assignment check
104 if (this != &graph) {
105 const_cast<nodes_t &>(nodes) = graph.nodes;
106 const_cast<edges_t &>(edges) = graph.edges;
107 }
108 return *this;
109}
[54a561]110
[e920d3d]111bool HomologyGraph::hasTimesAtomicNumber(const size_t _number, const size_t _times) const
112{
113 size_t count = 0;
114 for (nodes_t::const_iterator iter = nodes.begin(); iter != nodes.end(); ++iter) {
115 if ((iter->first).getAtomicNumber() == _number)
116 count += iter->second;
117 }
118 return (count == _times);
119}
120
[7c1091]121bool HomologyGraph::hasGreaterEqualTimesAtomicNumber(const size_t _number, const size_t _times) const
122{
123 size_t count = 0;
124 for (nodes_t::const_iterator iter = nodes.begin(); iter != nodes.end(); ++iter) {
125 if ((iter->first).getAtomicNumber() == _number)
126 count += iter->second;
127 }
128 return (count >= _times);
129}
130
[0afe00]131void HomologyGraph::printNodes(std::ostream& ost) const
[54a561]132{
[0afe00]133 for (nodes_t::const_iterator nodeiter = nodes.begin();
134 nodeiter != nodes.end();
[f7ce2b]135 ++nodeiter) {
[0afe00]136 if ( nodeiter != nodes.begin())
[f7ce2b]137 ost << ", ";
138 ost << nodeiter->second << "x " << nodeiter->first;
139 }
[0afe00]140}
141
142void HomologyGraph::printEdges(std::ostream& ost) const
143{
144 for (edges_t::const_iterator edgeiter = edges.begin();
145 edgeiter != edges.end();
[f7ce2b]146 ++edgeiter) {
[0afe00]147 if ( edgeiter != edges.begin())
[f7ce2b]148 ost << ", ";
149 ost << edgeiter->second << "x " << edgeiter->first;
150 }
[0afe00]151}
152
153std::ostream& operator<<(std::ostream& ost, const HomologyGraph &graph)
154{
155 graph.printNodes(ost);
156 graph.printEdges(ost);
[54a561]157 return ost;
158}
159
[a2a2f7]160//
161//// we need to explicitly instantiate the serialization functions
162//BOOST_CLASS_EXPORT_IMPLEMENT(HomologyGraph)
Note: See TracBrowser for help on using the repository browser.