Commit 5af02960 by maarten

multithreaded pepflip

git-svn-id: svn+ssh://gitlab/srv/svn-repos/pdb-redo/trunk@333 a1961a4f-ab94-4bcc-80e8-33b5a54de466
parent b450cdf1
......@@ -24,7 +24,7 @@ class DistanceMap
DistanceMap(const DistanceMap&) = delete;
DistanceMap& operator=(const DistanceMap&) = delete;
// float operator()(const Atom& a, const Atom& b) const;
float operator()(const Atom& a, const Atom& b) const;
std::vector<Atom> near(const Atom& a, float maxDistance = 3.5f) const;
std::vector<Atom> near(const Point& p, float maxDistance = 3.5f) const;
......
......@@ -66,6 +66,7 @@ class DSSP
SecondaryStructureType operator()(const Monomer& m) const;
bool isAlphaHelixEndBeforeStart(const Monomer& m) const;
bool isAlphaHelixEndBeforeStart(const std::string& inAsymID, int inSeqID) const;
private:
struct DSSPImpl* mImpl;
......
......@@ -87,6 +87,9 @@ class Atom
~Atom();
// return a copy of this atom, with data copied instead of referenced
Atom clone() const;
Atom& operator=(const Atom& rhs);
const std::string& id() const;
......@@ -130,8 +133,6 @@ class Atom
bool operator==(const Atom& rhs) const;
const File& getFile() const;
// get clipper format Atom
clipper::Atom toClipper() const;
......@@ -368,10 +369,12 @@ class Structure
{
public:
Structure(File& p, uint32 modelNr = 1);
Structure(const Structure&);
Structure& operator=(const Structure&);
Structure& operator=(const Structure&) = delete;
~Structure();
// Create a read-only clone of the current structure (for multithreaded calculations that move atoms)
Structure(const Structure&);
File& getFile() const;
AtomView atoms() const;
......
......@@ -230,42 +230,42 @@ DistanceMap::DistanceMap(const Structure& p, const clipper::Spacegroup& spacegro
// }
//}
//float DistanceMap::operator()(const Atom& a, const Atom& b) const
//{
// size_t ixa, ixb;
//
// try
// {
// ixa = index.at(a.id());
// }
// catch (const out_of_range& ex)
// {
// throw runtime_error("atom " + a.id() + " not found in distance map");
// }
//
// try
// {
// ixb = index.at(b.id());
// }
// catch (const out_of_range& ex)
// {
// throw runtime_error("atom " + b.id() + " not found in distance map");
// }
//
// if (ixb < ixa)
// swap(ixa, ixb);
//
// tuple<size_t,size_t> k{ ixa, ixb };
//
// auto ii = dist.find(k);
//
// float result = 100;
//
// if (ii != dist.end())
// result = ii->second;
//
// return result;
//}
float DistanceMap::operator()(const Atom& a, const Atom& b) const
{
size_t ixa, ixb;
try
{
ixa = index.at(a.id());
}
catch (const out_of_range& ex)
{
throw runtime_error("atom " + a.id() + " not found in distance map");
}
try
{
ixb = index.at(b.id());
}
catch (const out_of_range& ex)
{
throw runtime_error("atom " + b.id() + " not found in distance map");
}
if (ixb < ixa)
swap(ixa, ixb);
tuple<size_t,size_t> k{ ixa, ixb };
auto ii = dist.find(k);
float result = 100;
if (ii != dist.end())
result = get<0>(ii->second);
return result;
}
vector<Atom> DistanceMap::near(const Atom& a, float maxDistance) const
{
......
......@@ -860,18 +860,20 @@ SecondaryStructureType DSSP::operator()(const Monomer& m) const
bool DSSP::isAlphaHelixEndBeforeStart(const Monomer& m) const
{
auto asymID = m.asymID();
auto seqID = m.seqID();
return isAlphaHelixEndBeforeStart(m.asymID(), m.seqID());
}
bool DSSP::isAlphaHelixEndBeforeStart(const string& inAsymID, int inSeqID) const
{
auto i = find_if(mImpl->mResidues.begin(), mImpl->mResidues.end(),
[&](auto& r) { return r.mM.asymID() == asymID and r.mM.seqID() == seqID; });
[&](auto& r) { return r.mM.asymID() == inAsymID and r.mM.seqID() == inSeqID; });
bool result = false;
if (i != mImpl->mResidues.end() and i + 1 != mImpl->mResidues.end())
result = i->GetHelixFlag(4) == helixEnd and (i + 1)->GetHelixFlag(4) == helixStart;
else if (VERBOSE)
cerr << "Could not find secondary structure for " << asymID << ':' << seqID << endl;
cerr << "Could not find secondary structure for " << inAsymID << ':' << inSeqID << endl;
return result;
}
......
......@@ -145,6 +145,16 @@ void FileImpl::save(fs::path p)
struct AtomImpl
{
AtomImpl(const AtomImpl& i)
: mFile(i.mFile), mId(i.mId), mType(i.mType)
, mAtomID(i.mAtomID), mCompID(i.mCompID), mAsymID(i.mAsymID)
, mSeqID(i.mSeqID), mAltID(i.mAltID), mLocation(i.mLocation)
, mRefcount(1), mRow(i.mRow), mCompound(i.mCompound)
, mRadius(i.mRadius), mCachedProperties(i.mCachedProperties)
, mSymmetryCopy(i.mSymmetryCopy), mClone(true)
{
}
AtomImpl(const File& f, const string& id)
: mFile(f), mId(id), mRefcount(1), mCompound(nullptr)
{
......@@ -276,9 +286,12 @@ struct AtomImpl
if (mSymmetryCopy)
throw runtime_error("Moving symmetry copy");
mRow["Cartn_x"] = p.getX();
mRow["Cartn_y"] = p.getY();
mRow["Cartn_z"] = p.getZ();
if (not mClone)
{
mRow["Cartn_x"] = p.getX();
mRow["Cartn_y"] = p.getY();
mRow["Cartn_z"] = p.getZ();
}
// boost::format kPosFmt("%.3f");
//
......@@ -353,6 +366,7 @@ struct AtomImpl
map<string,string> mCachedProperties;
bool mSymmetryCopy = false;
bool mClone = false;
};
//Atom::Atom(const File& f, const string& id)
......@@ -365,6 +379,11 @@ Atom::Atom(AtomImpl* impl)
{
}
Atom Atom::clone() const
{
return Atom(new AtomImpl(*mImpl));
}
Atom::Atom(const Atom& rhs)
: mImpl(rhs.mImpl)
{
......@@ -545,12 +564,6 @@ bool Atom::operator==(const Atom& rhs) const
(&mImpl->mFile == &rhs.mImpl->mFile and mImpl->mId == rhs.mImpl->mId);
}
const File& Atom::getFile() const
{
assert(mImpl);
return mImpl->mFile;
}
clipper::Atom Atom::toClipper() const
{
return mImpl->toClipper();
......@@ -1141,6 +1154,14 @@ struct StructureImpl
}
}
StructureImpl(const StructureImpl& si)
: mFile(si.mFile), mModelNr(si.mModelNr)
{
mAtoms.reserve(si.mAtoms.size());
for (auto& atom: si.mAtoms)
mAtoms.emplace_back(atom.clone());
}
void removeAtom(Atom& a);
void swapAtoms(Atom& a1, Atom& a2);
void moveAtom(Atom& a, Point p);
......@@ -1310,6 +1331,11 @@ Structure::~Structure()
delete mImpl;
}
Structure::Structure(const Structure& rhs)
: mImpl(new StructureImpl(*rhs.mImpl))
{
}
AtomView Structure::atoms() const
{
return mImpl->mAtoms;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment