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
|
// -*- Mode: C++; tab-width: 2; -*-
// vi: set ts=2:
//
// $Id: partialChargeBase.C,v 1.2.28.1 2007-03-16 00:06:47 bertsch Exp $
//
#include <BALL/QSAR/partialChargeBase.h>
#include <BALL/QSAR/partialChargeProcessor.h>
#include <BALL/KERNEL/bond.h>
#include <BALL/KERNEL/bondIterator.h>
#include <BALL/KERNEL/atomIterator.h>
#include <BALL/KERNEL/forEach.h>
#include <BALL/KERNEL/fragment.h>
#include <BALL/KERNEL/PTE.h>
#include <BALL/CONCEPT/timeStamp.h>
#include <utility>
using namespace std;
namespace BALL
{
PartialChargeBase::PartialChargeBase()
: Descriptor()
{
data_folder_ = "QSAR/";
}
PartialChargeBase::PartialChargeBase(const PartialChargeBase& pcb)
: Descriptor(pcb)
{
data_folder_ = "QSAR/";
}
PartialChargeBase::PartialChargeBase(const String& name)
: Descriptor(name)
{
data_folder_ = "QSAR/";
}
PartialChargeBase::PartialChargeBase(const String& name, const String& unit)
: Descriptor(name, unit)
{
data_folder_ = "QSAR/";
}
PartialChargeBase::~PartialChargeBase()
{
}
PartialChargeBase& PartialChargeBase::operator = (const PartialChargeBase& pcb)
{
setName(pcb.getName());
setUnit(pcb.getUnit());
data_folder_ = pcb.data_folder_;
return *this;
}
bool PartialChargeBase::isValid_(AtomContainer& ac)
{
static HashMap<Handle, PreciseTime> mod_times;
PreciseTime last_mod = ac.getModificationTime();
Handle mol_handle = ac.getHandle();
if (mod_times.has(mol_handle))
{
if (mod_times[mol_handle] == last_mod)
{
return true;
}
else
{
mod_times[mol_handle] = last_mod;
return false;
}
}
else
{
mod_times.insert(std::make_pair(mol_handle, last_mod));
return false;
}
}
void PartialChargeBase::computeAllDescriptors(AtomContainer& ac)
{
if (!isValid_(ac))
{
calculate_(ac);
}
}
void PartialChargeBase::setDataFolder(const char* folder)
{
data_folder_ = folder;
}
void PartialChargeBase::calculate_(AtomContainer& ac)
{
// sets partial charges;
PartialChargeProcessor pcp;
pcp.setDataFolder(data_folder_.c_str());
ac.apply(pcp);
//HashMap<Atom*, double>::Iterator it = charges.begin();
AtomIterator it = ac.beginAtom();
// assign the calculated values to the descriptors
double tot_pos(0), tot_neg(0), rel_pos(0), rel_neg(0), max_charge(0), min_charge(0);
for (it = ac.beginAtom(); it != ac.endAtom(); ++it)
{
double charge = it->getProperty("PEOEPartialCharge").getDouble();
if (charge > 0)
{
tot_pos += charge;
}
else
{
tot_neg += charge;
}
if (charge > max_charge)
{
max_charge = charge;
}
if (charge < min_charge)
{
min_charge = charge;
}
// set partial charge as atom property
}
// this might be paranoid, but you never know
if (max_charge > 0 && tot_pos > 0)
{
rel_pos = max_charge/tot_pos;
}
// this might be also paranoid, but you still never know
if (min_charge < 0 && tot_neg < 0)
{
rel_neg = min_charge/tot_neg;
}
ac.setProperty("TotalPositivePartialCharge", tot_pos);
ac.setProperty("TotalNegativePartialCharge", tot_neg);
ac.setProperty("RelPositivePartialCharge", rel_pos);
ac.setProperty("RelNegativePartialCharge", rel_neg);
}
} // namespace BALL
|