Commit 4b4757ee by Maarten L. Hekkelman

removed using namespace std;

parent ac088dd0
...@@ -97,7 +97,6 @@ LIBCIF_SRC = AtomType.cpp \ ...@@ -97,7 +97,6 @@ LIBCIF_SRC = AtomType.cpp \
CifUtils.cpp \ CifUtils.cpp \
CifValidator.cpp \ CifValidator.cpp \
Compound.cpp \ Compound.cpp \
FixDMC.cpp \
PDB2Cif.cpp \ PDB2Cif.cpp \
PDB2CifRemark3.cpp \ PDB2CifRemark3.cpp \
Point.cpp \ Point.cpp \
......
...@@ -29,8 +29,6 @@ ...@@ -29,8 +29,6 @@
#include "cif++/AtomType.hpp" #include "cif++/AtomType.hpp"
#include "cif++/Cif++.hpp" #include "cif++/Cif++.hpp"
using namespace std;
namespace mmcif namespace mmcif
{ {
...@@ -1237,7 +1235,7 @@ SFDataArrayElement kELSFData[] = { ...@@ -1237,7 +1235,7 @@ SFDataArrayElement kELSFData[] = {
// -------------------------------------------------------------------- // --------------------------------------------------------------------
// AtomTypeTraits // AtomTypeTraits
AtomTypeTraits::AtomTypeTraits(const string& symbol) AtomTypeTraits::AtomTypeTraits(const std::string& symbol)
: mInfo(nullptr) : mInfo(nullptr)
{ {
for (auto& i: data::kKnownAtoms) for (auto& i: data::kKnownAtoms)
...@@ -1250,20 +1248,20 @@ AtomTypeTraits::AtomTypeTraits(const string& symbol) ...@@ -1250,20 +1248,20 @@ AtomTypeTraits::AtomTypeTraits(const string& symbol)
} }
if (mInfo == nullptr) if (mInfo == nullptr)
throw invalid_argument("Not a known element: " + symbol); throw std::invalid_argument("Not a known element: " + symbol);
} }
AtomTypeTraits::AtomTypeTraits(AtomType t) AtomTypeTraits::AtomTypeTraits(AtomType t)
{ {
if (t < H or t >= data::kKnownAtomsCount) if (t < H or t >= data::kKnownAtomsCount)
throw invalid_argument("atomType out of range"); throw std::invalid_argument("atomType out of range");
mInfo = &data::kKnownAtoms[t]; mInfo = &data::kKnownAtoms[t];
assert(mInfo->type == t); assert(mInfo->type == t);
} }
bool AtomTypeTraits::isElement(const string& symbol) bool AtomTypeTraits::isElement(const std::string& symbol)
{ {
bool result = false; bool result = false;
...@@ -1279,7 +1277,7 @@ bool AtomTypeTraits::isElement(const string& symbol) ...@@ -1279,7 +1277,7 @@ bool AtomTypeTraits::isElement(const string& symbol)
return result; return result;
} }
bool AtomTypeTraits::isMetal(const string& symbol) bool AtomTypeTraits::isMetal(const std::string& symbol)
{ {
bool result = false; bool result = false;
...@@ -1303,7 +1301,7 @@ auto AtomTypeTraits::wksf(int charge) const -> const SFData& ...@@ -1303,7 +1301,7 @@ auto AtomTypeTraits::wksf(int charge) const -> const SFData&
return sf.sf; return sf.sf;
} }
throw runtime_error("No scattering factor found for " + name() + to_string(charge)); throw std::runtime_error("No scattering factor found for " + name() + std::to_string(charge));
} }
auto AtomTypeTraits::elsf() const -> const SFData& auto AtomTypeTraits::elsf() const -> const SFData&
...@@ -1314,7 +1312,7 @@ auto AtomTypeTraits::elsf() const -> const SFData& ...@@ -1314,7 +1312,7 @@ auto AtomTypeTraits::elsf() const -> const SFData&
return sf.sf; return sf.sf;
} }
throw runtime_error("No scattering factor found for " + name()); throw std::runtime_error("No scattering factor found for " + name());
} }
} }
...@@ -47,7 +47,6 @@ ...@@ -47,7 +47,6 @@
#include "cif++/CifUtils.hpp" #include "cif++/CifUtils.hpp"
using namespace std;
namespace ba = boost::algorithm; namespace ba = boost::algorithm;
namespace cif namespace cif
...@@ -80,7 +79,7 @@ const uint8_t kCharToLowerMap[256] = ...@@ -80,7 +79,7 @@ const uint8_t kCharToLowerMap[256] =
// -------------------------------------------------------------------- // --------------------------------------------------------------------
bool iequals(const string& a, const string& b) bool iequals(const std::string& a, const std::string& b)
{ {
bool result = a.length() == b.length(); bool result = a.length() == b.length();
for (auto ai = a.begin(), bi = b.begin(); result and ai != a.end() and bi != b.end(); ++ai, ++bi) for (auto ai = a.begin(), bi = b.begin(); result and ai != a.end() and bi != b.end(); ++ai, ++bi)
...@@ -97,7 +96,7 @@ bool iequals(const char* a, const char* b) ...@@ -97,7 +96,7 @@ bool iequals(const char* a, const char* b)
return result and *a == *b; return result and *a == *b;
} }
int icompare(const string& a, const string& b) int icompare(const std::string& a, const std::string& b)
{ {
int d = 0; int d = 0;
auto ai = a.begin(), bi = b.begin(); auto ai = a.begin(), bi = b.begin();
...@@ -134,15 +133,15 @@ int icompare(const char* a, const char* b) ...@@ -134,15 +133,15 @@ int icompare(const char* a, const char* b)
return d; return d;
} }
void toLower(string& s) void toLower(std::string& s)
{ {
for (auto& c: s) for (auto& c: s)
c = tolower(c); c = tolower(c);
} }
string toLowerCopy(const string& s) std::string toLowerCopy(const std::string& s)
{ {
string result(s); std::string result(s);
for (auto& c: result) for (auto& c: result)
c = tolower(c); c = tolower(c);
return result; return result;
...@@ -150,17 +149,17 @@ string toLowerCopy(const string& s) ...@@ -150,17 +149,17 @@ string toLowerCopy(const string& s)
// -------------------------------------------------------------------- // --------------------------------------------------------------------
tuple<string,string> splitTagName(const string& tag) std::tuple<std::string,std::string> splitTagName(const std::string& tag)
{ {
if (tag.empty()) if (tag.empty())
throw runtime_error("empty tag"); throw std::runtime_error("empty tag");
if (tag[0] != '_') if (tag[0] != '_')
throw runtime_error("tag does not start with underscore"); throw std::runtime_error("tag does not start with underscore");
auto s = tag.find('.'); auto s = tag.find('.');
if (s == string::npos) if (s == std::string::npos)
throw runtime_error("tag does not contain dot"); throw std::runtime_error("tag does not contain dot");
return tuple<string,string>{ return std::tuple<std::string,std::string>{
tag.substr(1, s - 1), tag.substr(s + 1) tag.substr(1, s - 1), tag.substr(s + 1)
}; };
} }
...@@ -236,7 +235,7 @@ const LineBreakClass kASCII_LBTable[128] = ...@@ -236,7 +235,7 @@ const LineBreakClass kASCII_LBTable[128] =
kLBC_Alphabetic, kLBC_Alphabetic, kLBC_Alphabetic, kLBC_OpenPunctuation, kLBC_BreakAfter, kLBC_ClosePunctuation, kLBC_Alphabetic, kLBC_CombiningMark kLBC_Alphabetic, kLBC_Alphabetic, kLBC_Alphabetic, kLBC_OpenPunctuation, kLBC_BreakAfter, kLBC_ClosePunctuation, kLBC_Alphabetic, kLBC_CombiningMark
}; };
string::const_iterator nextLineBreak(string::const_iterator text, string::const_iterator end) std::string::const_iterator nextLineBreak(std::string::const_iterator text, std::string::const_iterator end)
{ {
if (text == end) if (text == end)
return text; return text;
...@@ -329,10 +328,10 @@ string::const_iterator nextLineBreak(string::const_iterator text, string::const_ ...@@ -329,10 +328,10 @@ string::const_iterator nextLineBreak(string::const_iterator text, string::const_
return text; return text;
} }
vector<string> wrapLine(const string& text, unsigned int width) std::vector<std::string> wrapLine(const std::string& text, unsigned int width)
{ {
vector<string> result; std::vector<std::string> result;
vector<size_t> offsets = { 0 }; std::vector<size_t> offsets = { 0 };
auto b = text.begin(); auto b = text.begin();
while (b != text.end()) while (b != text.end())
...@@ -346,9 +345,9 @@ vector<string> wrapLine(const string& text, unsigned int width) ...@@ -346,9 +345,9 @@ vector<string> wrapLine(const string& text, unsigned int width)
size_t count = offsets.size() - 1; size_t count = offsets.size() - 1;
vector<size_t> minima(count + 1, 1000000); std::vector<size_t> minima(count + 1, 1000000);
minima[0] = 0; minima[0] = 0;
vector<size_t> breaks(count + 1, 0); std::vector<size_t> breaks(count + 1, 0);
for (size_t i = 0; i < count; ++i) for (size_t i = 0; i < count; ++i)
{ {
...@@ -390,12 +389,12 @@ vector<string> wrapLine(const string& text, unsigned int width) ...@@ -390,12 +389,12 @@ vector<string> wrapLine(const string& text, unsigned int width)
return result; return result;
} }
vector<string> wordWrap(const string& text, unsigned int width) std::vector<std::string> wordWrap(const std::string& text, unsigned int width)
{ {
vector<string> paragraphs; std::vector<std::string> paragraphs;
ba::split(paragraphs, text, ba::is_any_of("\n")); ba::split(paragraphs, text, ba::is_any_of("\n"));
vector<string> result; std::vector<std::string> result;
for (auto& p: paragraphs) for (auto& p: paragraphs)
{ {
if (p.empty()) if (p.empty())
...@@ -420,7 +419,7 @@ uint32_t get_terminal_width() ...@@ -420,7 +419,7 @@ uint32_t get_terminal_width()
} }
// I don't have a windows machine to test the following code, please accept my apologies in case it fails... // I don't have a windows machine to test the following code, please accept my apologies in case it fails...
string GetExecutablePath() std::string GetExecutablePath()
{ {
WCHAR buffer[4096]; WCHAR buffer[4096];
...@@ -430,7 +429,7 @@ string GetExecutablePath() ...@@ -430,7 +429,7 @@ string GetExecutablePath()
wstring ws(buffer); wstring ws(buffer);
return string(ws.begin(), ws.end()); return std::string(ws.begin(), ws.end());
} }
#else #else
...@@ -447,11 +446,13 @@ uint32_t get_terminal_width() ...@@ -447,11 +446,13 @@ uint32_t get_terminal_width()
return result; return result;
} }
string get_executable_path() std::string get_executable_path()
{ {
using namespace std::literals;
char path[PATH_MAX] = ""; char path[PATH_MAX] = "";
if (readlink("/proc/self/exe", path, sizeof(path)) == -1) if (readlink("/proc/self/exe", path, sizeof(path)) == -1)
throw runtime_error("could not get exe path "s + strerror(errno)); throw std::runtime_error("could not get exe path "s + strerror(errno));
return { path }; return { path };
} }
...@@ -461,7 +462,7 @@ string get_executable_path() ...@@ -461,7 +462,7 @@ string get_executable_path()
struct ProgressImpl struct ProgressImpl
{ {
ProgressImpl(int64_t inMax, const string& inAction) ProgressImpl(int64_t inMax, const std::string& inAction)
: mMax(inMax), mConsumed(0), mAction(inAction), mMessage(inAction) : mMax(inMax), mConsumed(0), mAction(inAction), mMessage(inAction)
, mThread(std::bind(&ProgressImpl::Run, this)) , mThread(std::bind(&ProgressImpl::Run, this))
, mStart(boost::posix_time::second_clock::local_time()) {} , mStart(boost::posix_time::second_clock::local_time()) {}
...@@ -478,10 +479,10 @@ struct ProgressImpl ...@@ -478,10 +479,10 @@ struct ProgressImpl
void PrintDone(); void PrintDone();
int64_t mMax; int64_t mMax;
atomic<int64_t> mConsumed; std::atomic<int64_t> mConsumed;
int64_t mLastConsumed = 0; int64_t mLastConsumed = 0;
int mSpinnerIndex = 0; int mSpinnerIndex = 0;
string mAction, mMessage; std::string mAction, mMessage;
std::mutex mMutex; std::mutex mMutex;
std::thread mThread; std::thread mThread;
boost::timer::cpu_timer mTimer; boost::timer::cpu_timer mTimer;
...@@ -549,7 +550,7 @@ void ProgressImpl::PrintProgress() ...@@ -549,7 +550,7 @@ void ProgressImpl::PrintProgress()
uint32_t width = get_terminal_width(); uint32_t width = get_terminal_width();
string msg; std::string msg;
msg.reserve(width + 1); msg.reserve(width + 1);
if (mMessage.length() <= 20) if (mMessage.length() <= 20)
{ {
...@@ -604,23 +605,23 @@ void ProgressImpl::PrintProgress() ...@@ -604,23 +605,23 @@ void ProgressImpl::PrintProgress()
// msg += to_string(perc); // msg += to_string(perc);
// msg += '%'; // msg += '%';
cout << '\r' << msg; std::cout << '\r' << msg;
cout.flush(); std::cout.flush();
} }
void ProgressImpl::PrintDone() void ProgressImpl::PrintDone()
{ {
string msg = mAction + " done in " + mTimer.format(0, "%ts cpu / %ws wall"); std::string msg = mAction + " done in " + mTimer.format(0, "%ts cpu / %ws wall");
uint32_t width = get_terminal_width(); uint32_t width = get_terminal_width();
if (msg.length() < width) if (msg.length() < width)
msg += string(width - msg.length(), ' '); msg += std::string(width - msg.length(), ' ');
cout << '\r' << msg << endl; std::cout << '\r' << msg << std::endl;
} }
Progress::Progress(int64_t inMax, const string& inAction) Progress::Progress(int64_t inMax, const std::string& inAction)
: mImpl(nullptr) : mImpl(nullptr)
{ {
if (isatty(STDOUT_FILENO)) if (isatty(STDOUT_FILENO))
......
...@@ -34,7 +34,6 @@ ...@@ -34,7 +34,6 @@
#include "cif++/CifParser.hpp" #include "cif++/CifParser.hpp"
#include "cif++/CifValidator.hpp" #include "cif++/CifValidator.hpp"
using namespace std;
namespace ba = boost::algorithm; namespace ba = boost::algorithm;
extern int VERBOSE; extern int VERBOSE;
...@@ -42,19 +41,19 @@ extern int VERBOSE; ...@@ -42,19 +41,19 @@ extern int VERBOSE;
namespace cif namespace cif
{ {
ValidationError::ValidationError(const string& msg) ValidationError::ValidationError(const std::string& msg)
: mMsg(msg) : mMsg(msg)
{ {
} }
ValidationError::ValidationError(const string& cat, const string& item, const string& msg) ValidationError::ValidationError(const std::string& cat, const std::string& item, const std::string& msg)
: mMsg("When validating _" + cat + '.' + item + ": " + msg) : mMsg("When validating _" + cat + '.' + item + ": " + msg)
{ {
} }
// -------------------------------------------------------------------- // --------------------------------------------------------------------
DDL_PrimitiveType mapToPrimitiveType(const string& s) DDL_PrimitiveType mapToPrimitiveType(const std::string& s)
{ {
DDL_PrimitiveType result; DDL_PrimitiveType result;
if (iequals(s, "char")) if (iequals(s, "char"))
...@@ -90,7 +89,7 @@ int ValidateType::compare(const char* a, const char* b) const ...@@ -90,7 +89,7 @@ int ValidateType::compare(const char* a, const char* b) const
double db = strtod(b, nullptr); double db = strtod(b, nullptr);
auto d = da - db; auto d = da - db;
if (abs(d) > numeric_limits<double>::epsilon()) if (std::abs(d) > std::numeric_limits<double>::epsilon())
{ {
if (d > 0) if (d > 0)
result = 1; result = 1;
...@@ -177,12 +176,12 @@ int ValidateType::compare(const char* a, const char* b) const ...@@ -177,12 +176,12 @@ int ValidateType::compare(const char* a, const char* b) const
// //
// parent->mChildren.insert(this); // parent->mChildren.insert(this);
//// ////
//// if (mCategory->mKeys == vector<string>{mTag}) //// if (mCategory->mKeys == std::vector<std::string>{mTag})
//// parent->mForeignKeys.insert(this); //// parent->mForeignKeys.insert(this);
// } // }
//} //}
void ValidateItem::operator()(string value) const void ValidateItem::operator()(std::string value) const
{ {
if (not value.empty() and value != "?" and value != ".") if (not value.empty() and value != "?" and value != ".")
{ {
...@@ -206,19 +205,19 @@ void ValidateCategory::addItemValidator(ValidateItem&& v) ...@@ -206,19 +205,19 @@ void ValidateCategory::addItemValidator(ValidateItem&& v)
v.mCategory = this; v.mCategory = this;
auto r = mItemValidators.insert(move(v)); auto r = mItemValidators.insert(std::move(v));
if (not r.second and VERBOSE >= 4) if (not r.second and VERBOSE >= 4)
cout << "Could not add validator for item " << v.mTag << " to category " << mName << endl; std::cout << "Could not add validator for item " << v.mTag << " to category " << mName << std::endl;
} }
const ValidateItem* ValidateCategory::getValidatorForItem(string tag) const const ValidateItem* ValidateCategory::getValidatorForItem(std::string tag) const
{ {
const ValidateItem* result = nullptr; const ValidateItem* result = nullptr;
auto i = mItemValidators.find(ValidateItem{tag}); auto i = mItemValidators.find(ValidateItem{tag});
if (i != mItemValidators.end()) if (i != mItemValidators.end())
result = &*i; result = &*i;
else if (VERBOSE > 4) else if (VERBOSE > 4)
cout << "No validator for tag " << tag << endl; std::cout << "No validator for tag " << tag << std::endl;
return result; return result;
} }
...@@ -234,12 +233,12 @@ Validator::~Validator() ...@@ -234,12 +233,12 @@ Validator::~Validator()
void Validator::addTypeValidator(ValidateType&& v) void Validator::addTypeValidator(ValidateType&& v)
{ {
auto r = mTypeValidators.insert(move(v)); auto r = mTypeValidators.insert(std::move(v));
if (not r.second and VERBOSE > 4) if (not r.second and VERBOSE > 4)
cout << "Could not add validator for type " << v.mName << endl; std::cout << "Could not add validator for type " << v.mName << std::endl;
} }
const ValidateType* Validator::getValidatorForType(string typeCode) const const ValidateType* Validator::getValidatorForType(std::string typeCode) const
{ {
const ValidateType* result = nullptr; const ValidateType* result = nullptr;
...@@ -247,33 +246,33 @@ const ValidateType* Validator::getValidatorForType(string typeCode) const ...@@ -247,33 +246,33 @@ const ValidateType* Validator::getValidatorForType(string typeCode) const
if (i != mTypeValidators.end()) if (i != mTypeValidators.end())
result = &*i; result = &*i;
else if (VERBOSE > 4) else if (VERBOSE > 4)
cout << "No validator for type " << typeCode << endl; std::cout << "No validator for type " << typeCode << std::endl;
return result; return result;
} }
void Validator::addCategoryValidator(ValidateCategory&& v) void Validator::addCategoryValidator(ValidateCategory&& v)
{ {
auto r = mCategoryValidators.insert(move(v)); auto r = mCategoryValidators.insert(std::move(v));
if (not r.second and VERBOSE > 4) if (not r.second and VERBOSE > 4)
cout << "Could not add validator for category " << v.mName << endl; std::cout << "Could not add validator for category " << v.mName << std::endl;
} }
const ValidateCategory* Validator::getValidatorForCategory(string category) const const ValidateCategory* Validator::getValidatorForCategory(std::string category) const
{ {
const ValidateCategory* result = nullptr; const ValidateCategory* result = nullptr;
auto i = mCategoryValidators.find(ValidateCategory{category}); auto i = mCategoryValidators.find(ValidateCategory{category});
if (i != mCategoryValidators.end()) if (i != mCategoryValidators.end())
result = &*i; result = &*i;
else if (VERBOSE > 4) else if (VERBOSE > 4)
cout << "No validator for category " << category << endl; std::cout << "No validator for category " << category << std::endl;
return result; return result;
} }
ValidateItem* Validator::getValidatorForItem(string tag) const ValidateItem* Validator::getValidatorForItem(std::string tag) const
{ {
ValidateItem* result = nullptr; ValidateItem* result = nullptr;
string cat, item; std::string cat, item;
std::tie(cat, item) = splitTagName(tag); std::tie(cat, item) = splitTagName(tag);
auto* cv = getValidatorForCategory(cat); auto* cv = getValidatorForCategory(cat);
...@@ -281,7 +280,7 @@ ValidateItem* Validator::getValidatorForItem(string tag) const ...@@ -281,7 +280,7 @@ ValidateItem* Validator::getValidatorForItem(string tag) const
result = const_cast<ValidateItem*>(cv->getValidatorForItem(item)); result = const_cast<ValidateItem*>(cv->getValidatorForItem(item));
if (result == nullptr and VERBOSE > 4) if (result == nullptr and VERBOSE > 4)
cout << "No validator for item " << tag << endl; std::cout << "No validator for item " << tag << std::endl;
return result; return result;
} }
...@@ -290,38 +289,38 @@ void Validator::addLinkValidator(ValidateLink&& v) ...@@ -290,38 +289,38 @@ void Validator::addLinkValidator(ValidateLink&& v)
{ {
assert(v.mParentKeys.size() == v.mChildKeys.size()); assert(v.mParentKeys.size() == v.mChildKeys.size());
if (v.mParentKeys.size() != v.mChildKeys.size()) if (v.mParentKeys.size() != v.mChildKeys.size())
throw runtime_error("unequal number of keys for parent and child in link"); throw std::runtime_error("unequal number of keys for parent and child in link");
auto pcv = getValidatorForCategory(v.mParentCategory); auto pcv = getValidatorForCategory(v.mParentCategory);
auto ccv = getValidatorForCategory(v.mChildCategory); auto ccv = getValidatorForCategory(v.mChildCategory);
if (pcv == nullptr) if (pcv == nullptr)
throw runtime_error("unknown parent category " + v.mParentCategory); throw std::runtime_error("unknown parent category " + v.mParentCategory);
if (ccv == nullptr) if (ccv == nullptr)
throw runtime_error("unknown child category " + v.mChildCategory); throw std::runtime_error("unknown child category " + v.mChildCategory);
for (size_t i = 0; i < v.mParentKeys.size(); ++i) for (size_t i = 0; i < v.mParentKeys.size(); ++i)
{ {
auto piv = pcv->getValidatorForItem(v.mParentKeys[i]); auto piv = pcv->getValidatorForItem(v.mParentKeys[i]);
if (piv == nullptr) if (piv == nullptr)
throw runtime_error("unknown parent tag _" + v.mParentCategory + '.' + v.mParentKeys[i]); throw std::runtime_error("unknown parent tag _" + v.mParentCategory + '.' + v.mParentKeys[i]);
auto civ = ccv->getValidatorForItem(v.mChildKeys[i]); auto civ = ccv->getValidatorForItem(v.mChildKeys[i]);
if (civ == nullptr) if (civ == nullptr)
throw runtime_error("unknown child tag _" + v.mChildCategory + '.' + v.mChildKeys[i]); throw std::runtime_error("unknown child tag _" + v.mChildCategory + '.' + v.mChildKeys[i]);
if (civ->mType == nullptr and piv->mType != nullptr) if (civ->mType == nullptr and piv->mType != nullptr)
const_cast<ValidateItem*>(civ)->mType = piv->mType; const_cast<ValidateItem*>(civ)->mType = piv->mType;
} }
mLinkValidators.emplace_back(move(v)); mLinkValidators.emplace_back(std::move(v));
} }
vector<const ValidateLink*> Validator::getLinksForParent(const string& category) const std::vector<const ValidateLink*> Validator::getLinksForParent(const std::string& category) const
{ {
vector<const ValidateLink*> result; std::vector<const ValidateLink*> result;
for (auto& l: mLinkValidators) for (auto& l: mLinkValidators)
{ {
...@@ -332,9 +331,9 @@ vector<const ValidateLink*> Validator::getLinksForParent(const string& category) ...@@ -332,9 +331,9 @@ vector<const ValidateLink*> Validator::getLinksForParent(const string& category)
return result; return result;
} }
vector<const ValidateLink*> Validator::getLinksForChild(const string& category) const std::vector<const ValidateLink*> Validator::getLinksForChild(const std::string& category) const
{ {
vector<const ValidateLink*> result; std::vector<const ValidateLink*> result;
for (auto& l: mLinkValidators) for (auto& l: mLinkValidators)
{ {
...@@ -345,12 +344,12 @@ vector<const ValidateLink*> Validator::getLinksForChild(const string& category) ...@@ -345,12 +344,12 @@ vector<const ValidateLink*> Validator::getLinksForChild(const string& category)
return result; return result;
} }
void Validator::reportError(const string& msg, bool fatal) void Validator::reportError(const std::string& msg, bool fatal)
{ {
if (mStrict or fatal) if (mStrict or fatal)
throw ValidationError(msg); throw ValidationError(msg);
else if (VERBOSE) else if (VERBOSE)
cerr << msg << endl; std::cerr << msg << std::endl;
} }
} }
/*-
* SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2020 NKI/AVL, Netherlands Cancer Institute
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <set>
#include <cif++/Structure.hpp>
namespace mmcif
{
void addC(Monomer& mon)
{
}
void addCA(Monomer& mon)
{
}
void addN(Monomer& mon)
{
}
void addO(Monomer& mon)
{
}
void CreateMissingBackboneAtoms(Structure& structure, bool simplified)
{
for (auto& poly: structure.polymers())
{
for (auto& mon: poly)
{
if (mon.isComplete() or mon.hasAlternateBackboneAtoms())
continue;
auto atomC = mon.atomByID("C");
auto atomCA = mon.atomByID("CA");
auto atomN = mon.atomByID("N");
auto atomO = mon.atomByID("O");
int missing = (atomC ? 0 : 1) + (atomCA ? 0 : 1) + (atomN ? 0 : 1) + (atomO ? 0 : 1);
switch (missing)
{
case 1:
if (not atomO)
addO(mon);
else if (not atomN)
addN(mon);
else if (not atomCA)
addCA(mon);
else if (not atomC)
addC(mon);
break;
}
}
}
}
}
\ No newline at end of file
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -29,8 +29,6 @@ ...@@ -29,8 +29,6 @@
#include "cif++/Point.hpp" #include "cif++/Point.hpp"
using namespace std;
namespace mmcif namespace mmcif
{ {
...@@ -38,7 +36,7 @@ namespace mmcif ...@@ -38,7 +36,7 @@ namespace mmcif
quaternion Normalize(quaternion q) quaternion Normalize(quaternion q)
{ {
valarray<double> t(4); std::valarray<double> t(4);
t[0] = q.R_component_1(); t[0] = q.R_component_1();
t[1] = q.R_component_2(); t[1] = q.R_component_2();
...@@ -59,7 +57,7 @@ quaternion Normalize(quaternion q) ...@@ -59,7 +57,7 @@ quaternion Normalize(quaternion q)
// -------------------------------------------------------------------- // --------------------------------------------------------------------
tuple<double,Point> QuaternionToAngleAxis(quaternion q) std::tuple<double,Point> QuaternionToAngleAxis(quaternion q)
{ {
if (q.R_component_1() > 1) if (q.R_component_1() > 1)
q = Normalize(q); q = Normalize(q);
...@@ -75,10 +73,10 @@ tuple<double,Point> QuaternionToAngleAxis(quaternion q) ...@@ -75,10 +73,10 @@ tuple<double,Point> QuaternionToAngleAxis(quaternion q)
Point axis(q.R_component_2() / s, q.R_component_3() / s, q.R_component_4() / s); Point axis(q.R_component_2() / s, q.R_component_3() / s, q.R_component_4() / s);
return make_tuple(angle, axis); return std::make_tuple(angle, axis);
} }
Point CenterPoints(vector<Point>& Points) Point CenterPoints(std::vector<Point>& Points)
{ {
Point t; Point t;
...@@ -103,7 +101,7 @@ Point CenterPoints(vector<Point>& Points) ...@@ -103,7 +101,7 @@ Point CenterPoints(vector<Point>& Points)
return t; return t;
} }
Point Centroid(vector<Point>& Points) Point Centroid(std::vector<Point>& Points)
{ {
Point result; Point result;
...@@ -115,12 +113,12 @@ Point Centroid(vector<Point>& Points) ...@@ -115,12 +113,12 @@ Point Centroid(vector<Point>& Points)
return result; return result;
} }
double RMSd(const vector<Point>& a, const vector<Point>& b) double RMSd(const std::vector<Point>& a, const std::vector<Point>& b)
{ {
double sum = 0; double sum = 0;
for (uint32_t i = 0; i < a.size(); ++i) for (uint32_t i = 0; i < a.size(); ++i)
{ {
valarray<double> d(3); std::valarray<double> d(3);
d[0] = b[i].mX - a[i].mX; d[0] = b[i].mX - a[i].mX;
d[1] = b[i].mY - a[i].mY; d[1] = b[i].mY - a[i].mY;
...@@ -131,7 +129,7 @@ double RMSd(const vector<Point>& a, const vector<Point>& b) ...@@ -131,7 +129,7 @@ double RMSd(const vector<Point>& a, const vector<Point>& b)
sum += d.sum(); sum += d.sum();
} }
return sqrt(sum / a.size()); return std::sqrt(sum / a.size());
} }
// The next function returns the largest solution for a quartic equation // The next function returns the largest solution for a quartic equation
...@@ -145,30 +143,30 @@ double RMSd(const vector<Point>& a, const vector<Point>& b) ...@@ -145,30 +143,30 @@ double RMSd(const vector<Point>& a, const vector<Point>& b)
// sqrt of a negative number) // sqrt of a negative number)
double LargestDepressedQuarticSolution(double a, double b, double c) double LargestDepressedQuarticSolution(double a, double b, double c)
{ {
complex<double> P = - (a * a) / 12 - c; std::complex<double> P = - (a * a) / 12 - c;
complex<double> Q = - (a * a * a) / 108 + (a * c) / 3 - (b * b) / 8; std::complex<double> Q = - (a * a * a) / 108 + (a * c) / 3 - (b * b) / 8;
complex<double> R = - Q / 2.0 + sqrt((Q * Q) / 4.0 + (P * P * P) / 27.0); std::complex<double> R = - Q / 2.0 + std::sqrt((Q * Q) / 4.0 + (P * P * P) / 27.0);
complex<double> U = pow(R, 1 / 3.0); std::complex<double> U = std::pow(R, 1 / 3.0);
complex<double> y; std::complex<double> y;
if (U == 0.0) if (U == 0.0)
y = -5.0 * a / 6.0 + U - pow(Q, 1.0 / 3.0); y = -5.0 * a / 6.0 + U - std::pow(Q, 1.0 / 3.0);
else else
y = -5.0 * a / 6.0 + U - P / (3.0 * U); y = -5.0 * a / 6.0 + U - P / (3.0 * U);
complex<double> W = sqrt(a + 2.0 * y); std::complex<double> W = std::sqrt(a + 2.0 * y);
// And to get the final result: // And to get the final result:
// result = (±W + sqrt(-(3 * alpha + 2 * y ± 2 * beta / W))) / 2; // result = (±W + sqrt(-(3 * alpha + 2 * y ± 2 * beta / W))) / 2;
// We want the largest result, so: // We want the largest result, so:
valarray<double> t(4); std::valarray<double> t(4);
t[0] = (( W + sqrt(-(3.0 * a + 2.0 * y + 2.0 * b / W))) / 2.0).real(); t[0] = (( W + std::sqrt(-(3.0 * a + 2.0 * y + 2.0 * b / W))) / 2.0).real();
t[1] = (( W + sqrt(-(3.0 * a + 2.0 * y - 2.0 * b / W))) / 2.0).real(); t[1] = (( W + std::sqrt(-(3.0 * a + 2.0 * y - 2.0 * b / W))) / 2.0).real();
t[2] = ((-W + sqrt(-(3.0 * a + 2.0 * y + 2.0 * b / W))) / 2.0).real(); t[2] = ((-W + std::sqrt(-(3.0 * a + 2.0 * y + 2.0 * b / W))) / 2.0).real();
t[3] = ((-W + sqrt(-(3.0 * a + 2.0 * y - 2.0 * b / W))) / 2.0).real(); t[3] = ((-W + std::sqrt(-(3.0 * a + 2.0 * y - 2.0 * b / W))) / 2.0).real();
return t.max(); return t.max();
} }
...@@ -286,10 +284,10 @@ double LargestDepressedQuarticSolution(double a, double b, double c) ...@@ -286,10 +284,10 @@ double LargestDepressedQuarticSolution(double a, double b, double c)
Point Nudge(Point p, float offset) Point Nudge(Point p, float offset)
{ {
static std::random_device rd; static std::random_device rd;
static mt19937_64 rng(rd()); static std::mt19937_64 rng(rd());
uniform_real_distribution<> randomAngle(0, 2 * kPI); std::uniform_real_distribution<> randomAngle(0, 2 * kPI);
normal_distribution<> randomOffset(0, offset); std::normal_distribution<> randomOffset(0, offset);
float theta = randomAngle(rng); float theta = randomAngle(rng);
float phi1 = randomAngle(rng) - kPI; float phi1 = randomAngle(rng) - kPI;
......
...@@ -32,8 +32,6 @@ ...@@ -32,8 +32,6 @@
#include "cif++/Symmetry.hpp" #include "cif++/Symmetry.hpp"
#include "cif++/CifUtils.hpp" #include "cif++/CifUtils.hpp"
using namespace std;
namespace mmcif namespace mmcif
{ {
...@@ -51,7 +49,7 @@ int GetSpacegroupNumber(std::string spacegroup) ...@@ -51,7 +49,7 @@ int GetSpacegroupNumber(std::string spacegroup)
if (spacegroup == "P 21 21 2 A") if (spacegroup == "P 21 21 2 A")
spacegroup = "P 21 21 2 (a)"; spacegroup = "P 21 21 2 (a)";
else if (spacegroup.empty()) else if (spacegroup.empty())
throw runtime_error("No spacegroup, cannot continue"); throw std::runtime_error("No spacegroup, cannot continue");
int result = 0; int result = 0;
...@@ -88,7 +86,7 @@ int GetSpacegroupNumber(std::string spacegroup) ...@@ -88,7 +86,7 @@ int GetSpacegroupNumber(std::string spacegroup)
} }
if (result == 0) if (result == 0)
throw runtime_error("Spacegroup name " + spacegroup + " was not found in table"); throw std::runtime_error("Spacegroup name " + spacegroup + " was not found in table");
return result; return result;
} }
......
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