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:
//
#include <BALL/MOLMEC/AMBER/amberStretch.h>
#include <BALL/MOLMEC/AMBER/amber.h>
#include <BALL/KERNEL/bond.h>
#include <BALL/KERNEL/forEach.h>
using namespace std;
namespace BALL
{
// default constructor
AmberStretch::AmberStretch()
{
// set component name
setName( "Amber Stretch" );
}
// constructor
AmberStretch::AmberStretch(ForceField& force_field)
: StretchComponent(force_field)
{
// set component name
setName( "Amber Stretch" );
}
// destructor
AmberStretch::~AmberStretch()
{
}
// setup the internal datastructures for the component
bool AmberStretch::setup()
{
if (getForceField() == 0)
{
Log.error() << "AmberStretch::setup(): component not bound to force field" << endl;
return false;
}
// throw away the old contents
stretch_.clear();
Options& options = getForceField()->options;
if (options.has(AMBER_STRETCH_ENABLED))
{
if (!options.getBool(AMBER_STRETCH_ENABLED))
{
setEnabled(false);
return true;
}
else
{
setEnabled(true);
}
}
AmberFF* amber_force_field = dynamic_cast<AmberFF*>(force_field_);
if ((amber_force_field == 0) || !amber_force_field->hasInitializedParameters())
{
bool result = stretch_parameters_.extractSection(getForceField()->getParameters(), "QuadraticBondStretch");
if (!result)
{
Log.error() << "cannot find section QuadraticBondStretch" << endl;
return false;
}
}
QuadraticBondStretch::Values values;
bool use_selection = getForceField()->getUseSelection();
// retrieve all stretch parameters
Atom::BondIterator bond_iterator;
AtomVector::ConstIterator atom_it = getForceField()->getAtoms().begin();
for ( ; atom_it != getForceField()->getAtoms().end(); ++atom_it)
{
for (Atom::BondIterator it = (*atom_it)->beginBond(); +it ; ++it)
{
if (*atom_it == it->getFirstAtom())
{
Bond& bond = const_cast<Bond&>(*it);
if (bond.getType() == Bond::TYPE__HYDROGEN)
{
// Ignore hydrogen bonds!
continue;
}
if (!use_selection ||
(use_selection && bond.getFirstAtom()->isSelected() &&
bond.getSecondAtom()->isSelected()))
{
Atom::Type atom_type_A = bond.getFirstAtom()->getType();
Atom::Type atom_type_B = bond.getSecondAtom()->getType();
stretch_.push_back(QuadraticBondStretch::Data());
stretch_.back().atom1 = bond.getFirstAtom();
stretch_.back().atom2 = bond.getSecondAtom();
// Pay attention to the symmetric database input
if (stretch_parameters_.hasParameters(atom_type_A, atom_type_B))
{
stretch_parameters_.assignParameters(values, atom_type_A, atom_type_B);
}
else if (stretch_parameters_.hasParameters(atom_type_A, Atom::ANY_TYPE))
{
stretch_parameters_.assignParameters(values, atom_type_A, Atom::ANY_TYPE);
}
else if (stretch_parameters_.hasParameters(Atom::ANY_TYPE, atom_type_B))
{
stretch_parameters_.assignParameters(values, Atom::ANY_TYPE, atom_type_B);
}
else if (stretch_parameters_.hasParameters(Atom::ANY_TYPE, Atom::ANY_TYPE))
{
stretch_parameters_.assignParameters(values,Atom::ANY_TYPE, Atom::ANY_TYPE);
}
else
{
getForceField()->error() << "cannot find stretch parameters for atom types "
<< force_field_->getParameters().getAtomTypes().getTypeName(atom_type_A) << "-"
<< force_field_->getParameters().getAtomTypes().getTypeName(atom_type_B)
<< " (atoms are: "
<< stretch_.back().atom1->getFullName(Atom::ADD_VARIANT_EXTENSIONS_AND_ID)
<< "/" << stretch_.back().atom2->getFullName(
Atom::ADD_VARIANT_EXTENSIONS_AND_ID) << ")" << endl;
// we don't want to get any force or energy component
// from this stretch
values.k = 0.0;
values.r0 = 1.0;
getForceField()->getUnassignedAtoms().insert(bond.getFirstAtom());
getForceField()->getUnassignedAtoms().insert(bond.getSecondAtom());
}
stretch_.back().values = values;
}
}
}
}
// Everything went well.
return true;
}
} // namespace BALL
|