Skip to content
Snippets Groups Projects
Verified Commit f0ac4010 authored by Xavier Robin's avatar Xavier Robin
Browse files

feat: optionally ignore obsolete compounds

parent f5acb7f9
No related branches found
No related tags found
No related merge requests found
......@@ -42,16 +42,18 @@ void PrintUsage()
std::cout << "supported dialects are: pdb, charmm, amber, opls" << std::endl;
std::cout << "supported options are:" << std::endl;
std::cout << " -i - ignore compounds reserved by the PDB (01-99, DRG, INH, LIG)" << std::endl;
std::cout << " -o - ignore obsolete compounds" << std::endl;
}
int main(int argc, char const *argv[])
{
if (argc!=4 && argc!=5 && argc!=6) {
if (argc < 4) {
PrintUsage();
return 0;
}
conop::Compound::Dialect dialect=conop::Compound::PDB;
bool ignore_reserved=false;
bool ignore_obsolete=false;
for (int i = 4; i < argc; i++) {
String param=argv[i];
......@@ -65,6 +67,8 @@ int main(int argc, char const *argv[])
dialect=conop::Compound::AMBER;
} else if (param=="-i") {
ignore_reserved=true;
} else if (param=="-o") {
ignore_obsolete=true;
} else {
PrintUsage();
return 0;
......@@ -81,7 +85,7 @@ int main(int argc, char const *argv[])
filtered_istream.push(boost::iostreams::gzip_decompressor());
}
filtered_istream.push(istream);
io::ChemdictParser cdp(filtered_istream, dialect, ignore_reserved);
io::ChemdictParser cdp(filtered_istream, dialect, ignore_reserved, ignore_obsolete);
conop::CompoundLibPtr compound_lib;
bool in_mem=false;
if (!strncmp(argv[1], "create", 6)) {
......
......@@ -5,11 +5,7 @@ namespace ost { namespace io {
using namespace ost::conop;
bool ChemdictParser::OnBeginData(const StringRef& data_name)
{
if (data_name==StringRef("UNL",3)) {
compound_=CompoundPtr();
return false;
}
{
compound_.reset(new Compound(data_name.str()));
compound_->SetDialect(dialect_);
if (last_!=data_name[0]) {
......@@ -17,12 +13,6 @@ bool ChemdictParser::OnBeginData(const StringRef& data_name)
std::cout << last_ << std::flush;
}
atom_map_.clear();
if (ignore_reserved_ && IsNameReserved(data_name)) {
insert_=false;
}
else {
insert_=true;
}
return true;
}
......@@ -183,11 +173,17 @@ void ChemdictParser::OnDataItem(const StarDataItem& item)
void ChemdictParser::OnEndData()
{
if (insert_ && compound_) {
if (compound_->GetAtomSpecs().empty()) {
compound_->AddAtom(atom_);
if (compound_)
{
if (compound_->GetID() != "UNL" &&
! (ignore_reserved_ && IsNameReserved(compound_->GetID())) &&
! (ignore_obsolete_ && compound_->GetObsolete()))
{
if (compound_->GetAtomSpecs().empty()) {
compound_->AddAtom(atom_);
}
lib_->AddCompound(compound_);
}
lib_->AddCompound(compound_);
}
}
......@@ -257,7 +253,7 @@ void ChemdictParser::InitPDBXTypeMap()
xtm_["?"]=mol::ChemType(mol::ChemType::UNKNOWN);
}
bool ChemdictParser::IsNameReserved(const StringRef& data_name)
bool ChemdictParser::IsNameReserved(const String& data_name)
{
// This checks if the compound name is one of the reserved name that will
// never be used in the PDB. See
......@@ -266,10 +262,10 @@ bool ChemdictParser::IsNameReserved(const StringRef& data_name)
(data_name.length() == 2 &&
data_name[0] >= '0' && data_name[0] <= '9' &&
data_name[1] >= '0' && data_name[1] <= '9' &&
data_name != StringRef("00", 2)) ||
data_name == StringRef("DRG", 3) ||
data_name == StringRef("INH", 3) ||
data_name == StringRef("LIG", 3)
data_name != "00") ||
data_name == "DRG" ||
data_name == "INH" ||
data_name == "LIG"
)
{
std::cout << "Ignoring reserved compound " << data_name << std::endl;
......
......@@ -41,10 +41,10 @@ typedef enum {
class DLLEXPORT_OST_IO ChemdictParser : public StarParser {
public:
ChemdictParser(std::istream& stream, conop::Compound::Dialect dialect,
bool ignore_reserved=false):
bool ignore_reserved=false, bool ignore_obsolete=false):
StarParser(stream), compound_(new conop::Compound("UNK")),
last_(0), loop_type_(DONT_KNOW), dialect_(dialect),
ignore_reserved_(ignore_reserved)
ignore_reserved_(ignore_reserved), ignore_obsolete_(ignore_obsolete)
{
this->InitTypeMap();
this->InitPDBXTypeMap();
......@@ -68,7 +68,7 @@ public:
private:
void InitTypeMap();
void InitPDBXTypeMap();
bool IsNameReserved(const StringRef& data_name);
bool IsNameReserved(const String& data_name);
conop::CompoundLibPtr lib_;
conop::CompoundPtr compound_;
typedef enum {
......@@ -88,14 +88,14 @@ private:
} PropIndex;
char last_;
int indices_[10];
bool insert_;
static std::map<String, mol::ChemClass> tm_;
static std::map<String, mol::ChemClass> tm_;
static std::map<String, mol::ChemType> xtm_;
std::map<String, int> atom_map_;
LoopType loop_type_;
conop::AtomSpec atom_;
conop::Compound::Dialect dialect_;
bool ignore_reserved_;
bool ignore_obsolete_;
};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment