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 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168
|
#include <BALL/KERNEL/molecularInteractions.h>
using namespace BALL;
using std::map;
using std::make_pair;
bool MolecularInteractions::SAVE_ONLY_SUMS = 0;
MolecularInteractions::MolecularInteractions()
{
total_energy_ = 0;
threshold_ = 0.01; // by default save only interaction with strength >= 10 J/mol
}
void MolecularInteractions::clear()
{
interactions_map_.clear();
interaction_energies_.clear();
total_energy_ = 0;
}
void MolecularInteractions::setThreshold(double threshold)
{
threshold_ = fabs(threshold);
}
void MolecularInteractions::addInteraction(const Atom* atom, String interaction_type, double energy)
{
total_energy_+=energy;
map<String,double>::iterator s1 = interaction_energies_.find(interaction_type);
if(s1==interaction_energies_.end())
{
interaction_energies_.insert(make_pair(interaction_type,energy));
}
else
{
s1->second+=energy;
}
if(SAVE_ONLY_SUMS) return;
if(fabs(energy)>=threshold_)
{
map<String, map<const Atom*,double> >::iterator search_it = interactions_map_.find(interaction_type);
if(search_it==interactions_map_.end())
{
map<const Atom*,double> new_map;
interactions_map_.insert(make_pair(interaction_type,new_map));
search_it = interactions_map_.find(interaction_type);
}
search_it->second.insert(make_pair(atom,energy));
}
}
void MolecularInteractions::addInteraction(String interaction_type, double energy)
{
total_energy_+=energy;
map<String,double>::iterator s1 = interaction_energies_.find(interaction_type);
if(s1==interaction_energies_.end())
{
interaction_energies_.insert(make_pair(interaction_type,energy));
}
else
{
s1->second+=energy;
}
}
bool MolecularInteractions::hasInteraction(const Atom* atom, String interaction_type) const
{
map<String, map<const Atom*,double> >::const_iterator search_it = interactions_map_.find(interaction_type);
if(search_it==interactions_map_.end()) return false;
return search_it->second.find(atom)!=search_it->second.end();
}
double MolecularInteractions::getInteractionEnergy(const Atom* atom, String interaction_type) const
{
map<String, map<const Atom*,double> >::const_iterator search_it = interactions_map_.find(interaction_type);
if(search_it==interactions_map_.end()) return 0;
map<const Atom*,double>::const_iterator s2 = search_it->second.find(atom);
if(s2==search_it->second.end()) return 0;
else return s2->second;
}
double MolecularInteractions::getInteractionEnergy(const Atom* atom, const list<String>& interaction_types) const
{
double energy = 0;
for(list<String>::const_iterator it=interaction_types.begin(); it!=interaction_types.end(); it++)
{
energy+=getInteractionEnergy(atom,*it);
}
return energy;
}
const map<const Atom*,double>* MolecularInteractions::getInteractions(String interaction_type) const
{
map<String, map<const Atom*,double> >::const_iterator search_it = interactions_map_.find(interaction_type);
if(search_it!=interactions_map_.end()) return &search_it->second;
else return NULL;
}
void MolecularInteractions::getInteractions(const list<String>& interaction_types, map<const Atom*,double>& interactions) const
{
for(list<String>::const_iterator s_it=interaction_types.begin(); s_it!=interaction_types.end(); s_it++)
{
const map<const Atom*,double>* map_s = getInteractions(*s_it);
if(!map_s) continue;
if(s_it==interaction_types.begin())
{
interactions = *map_s;
continue;
}
for(map<const Atom*,double>::const_iterator it=map_s->begin(); it!=map_s->end(); it++)
{
map<const Atom*,double>::iterator search_it=interactions.find(it->first);
if(search_it==interactions.end())
{
interactions.insert(make_pair(it->first,it->second));
}
else
{
search_it->second+=it->second;
}
}
}
}
double MolecularInteractions::getInteractionEnergy(String interaction_type) const
{
map<String,double>::const_iterator s1 = interaction_energies_.find(interaction_type);
if(s1!=interaction_energies_.end())
{
return s1->second;
}
else return 0;
}
double MolecularInteractions::getInteractionEnergy(const list<String>& interaction_types) const
{
double energy=0;
for(list<String>::const_iterator it=interaction_types.begin(); it!=interaction_types.end(); it++)
{
energy += getInteractionEnergy(*it);
}
return energy;
}
double MolecularInteractions::getInteractionEnergy() const
{
return total_energy_;
}
|