Skip to content

Commit

Permalink
Reduce the scope of the public interface to coordgen (#84)
Browse files Browse the repository at this point in the history
* SHARED-7356: Reduce the scope of the public interface to coordgen

Made all fields in the skethcerMinimizer class private, and added
appropriate getters, setters, and other methods to interact with
CoordgenMinimizer and CoordgenFragmentBuilder. Requires a few
updates to CoordGen.h in RDKit.

* SHARED-7356: Reduce the scope of the public interface to coordgen

Made all fields in the skethcerMinimizer class private, and added
appropriate getters, setters, and other methods to interact with
CoordgenMinimizer and CoordgenFragmentBuilder. Requires a few
updates to CoordGen.h in RDKit.

* SHARED-7356: Reduce the scope of the public interface to coordgen

Made all fields in the skethcerMinimizer class private, and added
appropriate getters, setters, and other methods to interact with
CoordgenMinimizer and CoordgenFragmentBuilder. Requires a few
updates to CoordGen.h in RDKit.

* Added sketcherMinimizer::getBendInteractions

* Added  prefix to CoordgenMinimizer fields

* Added prefix to CoordgenMinimizer fields

* Reduce scope of sketcherMinimizer public interface

Made most methods unused outside of sketcherMinimizer private, and made all getters const.

* Reduce scope of sketcherMinimizer public interface

Made most methods unused outside of sketcherMinimizer private, and made all getters const.

* Moved a couple functions back to public that were used in maestro-src

* Updated test

* Exported CoordgenMacrocycleBuilder and CoordgenFragmentBuilder

This is so these classes can be accessed in test_coordgen.cpp.
 #Please enter the commit message for your changes. Lines starting

* Fixed merge conflict
  • Loading branch information
rachelnwalker authored Sep 7, 2021
1 parent 6413711 commit fa0a058
Show file tree
Hide file tree
Showing 6 changed files with 442 additions and 299 deletions.
8 changes: 4 additions & 4 deletions CoordgenMacrocycleBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -763,8 +763,8 @@ bool CoordgenMacrocycleBuilder::openCycleAndGenerateCoords(
{
map<sketcherMinimizerAtom*, sketcherMinimizerAtom*> atomMap;
sketcherMinimizer min(getPrecision());
min.m_minimizer.skipMinimization = true;
min.m_fragmentBuilder.setForceOpenMacrocycles(true);
min.setSkipMinimization(true);
min.setForceOpenMacrocycles(true);
auto* minMol = new sketcherMinimizerMolecule;
sketcherMinimizerBond* bondToBreak = findBondToOpen(ring);
if (!bondToBreak) {
Expand Down Expand Up @@ -805,7 +805,7 @@ bool CoordgenMacrocycleBuilder::openCycleAndGenerateCoords(
}
min.initialize(minMol);
min.findFragments();
min.m_minimizer.buildFromFragments(true);
min.buildFromFragments(true);
auto* brokenBond = new sketcherMinimizerBond;
brokenBond->bondOrder = bondToBreak->bondOrder;
brokenBond->startAtom = atomMap[bondToBreak->startAtom];
Expand All @@ -816,7 +816,7 @@ bool CoordgenMacrocycleBuilder::openCycleAndGenerateCoords(
std::vector<sketcherMinimizerInteraction*> extraInteractions;
extraInteractions.push_back(new sketcherMinimizerStretchInteraction(
brokenBond->startAtom, brokenBond->endAtom));
min.m_minimizer.avoidClashesOfMolecule(minMol, extraInteractions);
min.avoidClashesOfMolecule(minMol, extraInteractions);

for (sketcherMinimizerAtom* atom : atoms) {
sketcherMinimizerAtom* otherAtom = atomMap[atom];
Expand Down
42 changes: 21 additions & 21 deletions CoordgenMinimizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,21 +85,21 @@ void CoordgenMinimizer::run()
#endif

std::vector<float> local_energy_list(m_maxIterations);
std::vector<sketcherMinimizerPointF> lowest_energy_coords(_atoms.size());
std::vector<sketcherMinimizerPointF> lowest_energy_coords(m_atoms.size());
float min_energy = std::numeric_limits<float>::max();
for (unsigned int iterations = 0; iterations < m_maxIterations; ++iterations) {
local_energy_list[iterations] = scoreInteractions();
// track coordinates with lowest energy
if (local_energy_list[iterations] < min_energy) {
for (size_t i = 0; i < _atoms.size(); ++i) {
lowest_energy_coords[i] = _atoms[i]->coordinates;
for (size_t i = 0; i < m_atoms.size(); ++i) {
lowest_energy_coords[i] = m_atoms[i]->coordinates;
}
}
#ifdef DEBUG_MINIMIZATION_COORDINATES
// store data from this minimization step to be written to a file later
energy_list.push_back(local_energy_list[iterations]);
std::vector<sketcherMinimizerPointF> these_coordinates;
for (auto atom : _atoms) {
for (auto atom : m_atoms) {
these_coordinates.push_back(atom->coordinates);
}
all_coordinates.push_back(these_coordinates);
Expand All @@ -116,8 +116,8 @@ void CoordgenMinimizer::run()
}
// set coordinates back to lowest energy state
if (min_energy < std::numeric_limits<float>::max()) {
for (size_t i = 0; i < _atoms.size(); ++i) {
_atoms[i]->coordinates = lowest_energy_coords[i];
for (size_t i = 0; i < m_atoms.size(); ++i) {
m_atoms[i]->coordinates = lowest_energy_coords[i];
}
}
}
Expand All @@ -126,7 +126,7 @@ bool CoordgenMinimizer::applyForces(float maxd)
{
float delta = 0.001f; // minimum squared displacement
float distance = 0.f;
for (auto atom : _atoms) {
for (auto atom : m_atoms) {
if (atom->fixed) {
continue;
}
Expand Down Expand Up @@ -267,7 +267,7 @@ void CoordgenMinimizer::addStretchInteractionsOfMolecule(
/* return a set of all carbons part of a carbonyl group, i.e. doubly bonded to
* an oxygen. */
std::set<sketcherMinimizerAtom*> CoordgenMinimizer::getChetoCs(
const std::vector<sketcherMinimizerAtom*>& allAtoms)
const std::vector<sketcherMinimizerAtom*>& allAtoms) const
{
std::set<sketcherMinimizerAtom*> chetoCs;
for (auto atom : allAtoms) {
Expand All @@ -290,7 +290,7 @@ std::set<sketcherMinimizerAtom*> CoordgenMinimizer::getChetoCs(
/* return a set of all amino nitrogens. Not chemically accurate, doesn't filter
* out nitro Ns for instance. */
std::set<sketcherMinimizerAtom*> CoordgenMinimizer::getAminoNs(
const std::vector<sketcherMinimizerAtom*>& allAtoms)
const std::vector<sketcherMinimizerAtom*>& allAtoms) const
{
std::set<sketcherMinimizerAtom*> aminoNs;
for (auto atom : allAtoms) {
Expand All @@ -307,7 +307,7 @@ std::set<sketcherMinimizerAtom*> CoordgenMinimizer::getAminoNs(
std::set<sketcherMinimizerAtom*> CoordgenMinimizer::getAlphaCs(
const std::vector<sketcherMinimizerAtom*>& allAtoms,
const std::set<sketcherMinimizerAtom*>& chetoCs,
const std::set<sketcherMinimizerAtom*>& aminoNs)
const std::set<sketcherMinimizerAtom*>& aminoNs) const
{
std::set<sketcherMinimizerAtom*> alphaCs;
for (auto atom : allAtoms) {
Expand Down Expand Up @@ -668,8 +668,8 @@ void CoordgenMinimizer::addInteractionsOfMolecule(
void CoordgenMinimizer::setupInteractionsOnlyResidues()
{
const float CLASH_DISTANCE = bondLength * 1.5f;
for (auto res : _residues) {
for (auto res2 : _residues) {
for (auto res : m_residues) {
for (auto res2 : m_residues) {
if (res2 >= res) {
continue;
}
Expand Down Expand Up @@ -711,7 +711,7 @@ void CoordgenMinimizer::setupInteractionsProteinOnly(
void CoordgenMinimizer::setupInteractions(bool intrafragmentClashes)
{
clearInteractions();
for (sketcherMinimizerMolecule* molecule : _molecules) {
for (sketcherMinimizerMolecule* molecule : m_molecules) {
addInteractionsOfMolecule(molecule, intrafragmentClashes);
}
}
Expand Down Expand Up @@ -863,8 +863,8 @@ float CoordgenMinimizer::scoreCrossBonds(sketcherMinimizerMolecule* molecule,
}
}
}
if (_residueInteractions.size() && residueInteractions) {
for (auto r : _residues) {
if (m_residueInteractions.size() && residueInteractions) {
for (auto r : m_residues) {
if (r->residueInteractions.size() > 1) {
for (unsigned int ri1 = 0;
ri1 < r->residueInteractions.size() - 1; ri1++) {
Expand All @@ -884,7 +884,7 @@ float CoordgenMinimizer::scoreCrossBonds(sketcherMinimizerMolecule* molecule,
out += 15.f;
}

for (auto b2 : _bonds) {
for (auto b2 : m_bonds) {
if (b2->startAtom ==
r->residueInteractions[ri1]->endAtom) {
continue;
Expand Down Expand Up @@ -921,7 +921,7 @@ float CoordgenMinimizer::scoreAtomsInsideRings() const
{
float out = 0.f;
float cutOff = bondLength;
for (sketcherMinimizerMolecule* m : _molecules) {
for (sketcherMinimizerMolecule* m : m_molecules) {
for (sketcherMinimizerRing* r : m->_rings) {
if (r->_atoms.size() > MACROCYCLE) {
continue;
Expand Down Expand Up @@ -964,7 +964,7 @@ float CoordgenMinimizer::scoreAtomsInsideRings() const
float CoordgenMinimizer::scoreProximityRelationsOnOppositeSides() const
{
float out = 0.f;
for (sketcherMinimizerMolecule* m : _molecules) {
for (sketcherMinimizerMolecule* m : m_molecules) {
if (m->_atoms.size() < 2) {
continue;
}
Expand Down Expand Up @@ -1283,7 +1283,7 @@ bool CoordgenMinimizer::avoidClashes()
if (skipAvoidClashes) {
return true;
}
for (sketcherMinimizerMolecule* molecule : _molecules) {
for (sketcherMinimizerMolecule* molecule : m_molecules) {
auto cleanPose = avoidClashesOfMolecule(molecule);
allCleanPoses = allCleanPoses && cleanPose;
}
Expand Down Expand Up @@ -1483,7 +1483,7 @@ void CoordgenMinimizer::buildMoleculeFromFragments(

void CoordgenMinimizer::buildFromFragments(bool firstTime) const
{
for (sketcherMinimizerMolecule* molecule : _molecules) {
for (sketcherMinimizerMolecule* molecule : m_molecules) {
buildMoleculeFromFragments(molecule, firstTime);
}
}
Expand Down Expand Up @@ -1523,7 +1523,7 @@ bool CoordgenMinimizer::hasNaNCoordinates(

bool CoordgenMinimizer::hasNaNCoordinates()
{
return hasNaNCoordinates(_atoms);
return hasNaNCoordinates(m_atoms);
}

void CoordgenMinimizer::checkForClashes(sketcherMinimizerAtom* a)
Expand Down
24 changes: 12 additions & 12 deletions CoordgenMinimizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -278,17 +278,17 @@ class EXPORT_COORDGEN CoordgenMinimizer

/* find a list of carbons from the backbone C=O of a peptide */
std::set<sketcherMinimizerAtom*>
getChetoCs(const std::vector<sketcherMinimizerAtom*>& allAtoms);
getChetoCs(const std::vector<sketcherMinimizerAtom*>& allAtoms) const;

/* find a list of nitrogens from the backbon NH of a peptide */
std::set<sketcherMinimizerAtom*>
getAminoNs(const std::vector<sketcherMinimizerAtom*>& allAtoms);
getAminoNs(const std::vector<sketcherMinimizerAtom*>& allAtoms) const;

/* find a list of alpha carbons of a peptide */
std::set<sketcherMinimizerAtom*>
getAlphaCs(const std::vector<sketcherMinimizerAtom*>& allAtoms,
const std::set<sketcherMinimizerAtom*>& chetoCs,
const std::set<sketcherMinimizerAtom*>& aminoNs);
const std::set<sketcherMinimizerAtom*>& aminoNs) const;

/* check the atom for clashes with other atoms */
static void checkForClashes(sketcherMinimizerAtom* a);
Expand Down Expand Up @@ -317,22 +317,22 @@ class EXPORT_COORDGEN CoordgenMinimizer
void addExtraInteraction(sketcherMinimizerMolecule* molecule,
sketcherMinimizerInteraction* interaction);

std::vector<sketcherMinimizerAtom*> _atoms;
std::vector<sketcherMinimizerBond*> _bonds;
std::vector<sketcherMinimizerAtom*> m_atoms;
std::vector<sketcherMinimizerBond*> m_bonds;
bool m_evenAngles;
std::vector<sketcherMinimizerResidue*> _residues;
std::vector<sketcherMinimizerResidueInteraction*> _residueInteractions;
std::vector<sketcherMinimizerFragment*> _fragments;
std::vector<sketcherMinimizerMolecule*> _molecules;
std::vector<sketcherMinimizerResidue*> m_residues;
std::vector<sketcherMinimizerResidueInteraction*> m_residueInteractions;
std::vector<sketcherMinimizerFragment*> m_fragments;
std::vector<sketcherMinimizerMolecule*> m_molecules;
std::vector<float> energy_list;
std::vector<std::vector<sketcherMinimizerPointF>> all_coordinates;

bool skipMinimization, skipAvoidClashes, skipFlipFragments,
m_scoreResidueInteractions;

std::vector<sketcherMinimizerBendInteraction*> getBendInteractions() {return _bendInteractions;};
std::vector<sketcherMinimizerStretchInteraction*> getStretchInteractions() {return _stretchInteractions;};
std::vector<sketcherMinimizerInteraction*> getInteractions() {return _interactions;};
const std::vector<sketcherMinimizerBendInteraction*>& getBendInteractions() const {return _bendInteractions;};
const std::vector<sketcherMinimizerStretchInteraction*>& getStretchInteractions() const {return _stretchInteractions;};
const std::vector<sketcherMinimizerInteraction*>& getInteractions() const {return _interactions;};


/*
Expand Down
Loading

0 comments on commit fa0a058

Please sign in to comment.