From 9b00ef5bd8cab68e0669841db63a0a935764db49 Mon Sep 17 00:00:00 2001
From: Ansgar Philippsen <ansgar.philippsen@gmail.com>
Date: Tue, 22 Feb 2011 17:26:44 -0500
Subject: [PATCH] fixed mae loader connectivity logic; added generic peptide to
 heuristic builder

---
 modules/conop/src/heuristic_builder.cc       | 26 +++++-
 modules/conop/src/heuristic_builder.hh       |  3 +
 modules/conop/src/heuristic_connect_table.hh |  8 ++
 modules/io/src/mol/entity_io_mae_handler.cc  |  5 +-
 modules/io/src/mol/entity_io_mae_handler.hh  | 83 --------------------
 5 files changed, 38 insertions(+), 87 deletions(-)

diff --git a/modules/conop/src/heuristic_builder.cc b/modules/conop/src/heuristic_builder.cc
index c23860e90..3fbff0b9d 100644
--- a/modules/conop/src/heuristic_builder.cc
+++ b/modules/conop/src/heuristic_builder.cc
@@ -109,7 +109,8 @@ ConnResEntry::TorsionEntryList ConnResEntry::GetTorsionList() const
 // actual builder
 
 HeuristicBuilder::HeuristicBuilder():
-  emap_()
+  emap_(),
+  default_peptide_()
 {
   int def_entry_count = sizeof(heuristic_connect::def_entry_table)/sizeof(heuristic_connect::CONN_DEF_ENTRY);
 
@@ -180,8 +181,11 @@ HeuristicBuilder::HeuristicBuilder():
 
       entry.AddTors(tor_nam[0],tor_nam[1],tor_nam[2],tor_nam[3],tor_nam2);
     }
-
-    emap_[def_entry.abbrev]=entry;
+    if(ec==0) { 
+      default_peptide_=entry;
+    } else {
+      emap_[def_entry.abbrev]=entry;
+    }
   }
   LOG_DEBUG("done importing internal tables");
 }
@@ -294,6 +298,22 @@ void ConnectPrevNext(HeuristicBuilder* builder,mol::ResidueHandle res0,
   std::pair<detail::ConnResEntry,bool> res0_ret = builder->LookupResEntry(res0.GetKey());
   std::pair<detail::ConnResEntry,bool> res1_ret = builder->LookupResEntry(res1.GetKey());
 
+  if(!res0_ret.second) {
+    if(res0.FindAtom("N") && res0.FindAtom("CA") && res0.FindAtom("C")) {
+      LOG_DEBUG("using default peptide for " << res0.GetKey());
+      res0_ret.first=builder->DefaultPeptide();
+      res0_ret.second=true;
+    }
+  }
+
+  if(!res1_ret.second) {
+    if(res1.FindAtom("N") && res1.FindAtom("CA") && res1.FindAtom("C")) {
+      LOG_DEBUG("using default peptide for " << res1.GetKey());
+      res1_ret.first=builder->DefaultPeptide();
+      res1_ret.second=true;
+    }
+  }
+
   if(res0_ret.second && res1_ret.second) {
     detail::ConnResEntry& res0_centry=res0_ret.first;
     detail::ConnResEntry& res1_centry=res1_ret.first;
diff --git a/modules/conop/src/heuristic_builder.hh b/modules/conop/src/heuristic_builder.hh
index d6eca8b4d..05c9fe311 100644
--- a/modules/conop/src/heuristic_builder.hh
+++ b/modules/conop/src/heuristic_builder.hh
@@ -108,12 +108,15 @@ public:
   std::pair<detail::ConnResEntry,bool> LookupResEntry(const mol::ResidueKey& key);
   
   virtual void FillAtomProps(mol::AtomHandle atom);
+
+  const detail::ConnResEntry& DefaultPeptide() const {return default_peptide_;}
 protected:
   void ConnectivityFromAtomNames(const mol::ResidueHandle& res,
                                  detail::ConnResEntry& centry,
                                  mol::AtomHandleList& unknown_atoms);
 private:
   detail::ConnResEntryMap emap_;
+  detail::ConnResEntry default_peptide_;
 };
 
 
diff --git a/modules/conop/src/heuristic_connect_table.hh b/modules/conop/src/heuristic_connect_table.hh
index ae200aac1..69cd08920 100644
--- a/modules/conop/src/heuristic_connect_table.hh
+++ b/modules/conop/src/heuristic_connect_table.hh
@@ -41,6 +41,14 @@ struct CONN_DEF_ENTRY {
 };
 
 CONN_DEF_ENTRY def_entry_table[]={
+  // the first entry must be this generic one
+  {"Generic","___",'_', mol::ChemClass(mol::ChemClass::LPeptideLinking),
+   {"N","CA","C"},3,
+   {{-2,1}, {1,2}, {2,3}, {3,-3}},4,
+   {
+   },0,
+   {0, 0, 0, 0, 0, 0},6
+  },
   {"Alanine","ALA",'A', mol::ChemClass(mol::ChemClass::LPeptideLinking),
    {"N","CA","C","O","CB","OXT"},6,
    {{-2,1}, {1,2}, {2,3}, {3,4}, {2,5}, {3,-3}, {6, 3}},7,
diff --git a/modules/io/src/mol/entity_io_mae_handler.cc b/modules/io/src/mol/entity_io_mae_handler.cc
index 19c9e4067..7cccf154a 100644
--- a/modules/io/src/mol/entity_io_mae_handler.cc
+++ b/modules/io/src/mol/entity_io_mae_handler.cc
@@ -35,6 +35,7 @@
 
 #include <ost/log.hh>
 #include <ost/conop/conop.hh>
+#include <ost/conop/heuristic_builder.hh>
 #include <ost/mol/xcs_editor.hh>
 #include <ost/profile.hh>
 
@@ -272,6 +273,7 @@ void MAEReader::add_atom(mol::EntityHandle ent,
 
   // finally add atom
   LOG_TRACE("  atom " << aname << " (" << ele << ") @" << apos);
+  ++atom_count_;
   mol::AtomHandle ah = editor.InsertAtom(curr_residue_, aname, apos, ele);
 }
   
@@ -329,7 +331,8 @@ bool EntityIOMAEHandler::ProvidesExport(const boost::filesystem::path& loc,
 mol::EntityHandle LoadMAE(const String& file_name) 
 {
   Profile profile_load("LoadMAE");
-  conop::BuilderP builder = conop::Conopology::Instance().GetBuilder();  
+  //conop::BuilderP builder = conop::Conopology::Instance().GetBuilder();  
+  conop::BuilderP builder(new conop::HeuristicBuilder);
   MAEReader reader(file_name);
   mol::EntityHandle ent=mol::CreateEntity();
   mol::XCSEditor editor=ent.EditXCS(mol::BUFFERED_EDIT);
diff --git a/modules/io/src/mol/entity_io_mae_handler.hh b/modules/io/src/mol/entity_io_mae_handler.hh
index d464e5ab6..9a50d6e3f 100644
--- a/modules/io/src/mol/entity_io_mae_handler.hh
+++ b/modules/io/src/mol/entity_io_mae_handler.hh
@@ -74,89 +74,6 @@ public:
 };
 
 
-typedef EntityIOHandlerFactory<EntityIOMAEHandler> EntityIOMAEHandlerFactory;
-
-mol::EntityHandle DLLEXPORT_OST_IO LoadMAE(const String& file_name);
-
-}} // ns
-
-#endif
-//------------------------------------------------------------------------------
-// This file is part of the OpenStructure project <www.openstructure.org>
-//
-// Copyright (C) 2008-2011 by the OpenStructure authors
-//
-// This library is free software; you can redistribute it and/or modify it under
-// the terms of the GNU Lesser General Public License as published by the Free
-// Software Foundation; either version 3.0 of the License, or (at your option)
-// any later version.
-// This library is distributed in the hope that it will be useful, but WITHOUT
-// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
-// FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
-// details.
-//
-// You should have received a copy of the GNU Lesser General Public License
-// along with this library; if not, write to the Free Software Foundation, Inc.,
-// 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
-//------------------------------------------------------------------------------
-#ifndef OST_IO_ENTITY_IO_PLUGIN_MAE_H
-#define OST_IO_ENTITY_IO_PLUGIN_MAE_H
-
-#include <ost/io/mol/entity_io_handler.hh>
-
-#include <boost/iostreams/filtering_stream.hpp>
-#include <boost/filesystem/fstream.hpp>
-
-namespace ost { namespace io {
-
-class DLLEXPORT_OST_IO MAEReader {
-public:
-  MAEReader(const boost::filesystem::path& loc);
-  
-  void Import(mol::EntityHandle& ent);
-
-private:
-
-  void add_atom(mol::EntityHandle ent,
-                mol::XCSEditor& editor,const std::string& s_aname, 
-                const std::string& s_axpos, 
-                const std::string& s_aypos, 
-                const std::string& s_azpos, 
-                const std::string& s_rname,
-                const std::string& s_rnum,
-                const std::string& s_cname);
-
-  mol::ChainHandle curr_chain_;
-  mol::ResidueHandle curr_residue_;
-  int chain_count_;
-  int residue_count_;
-  int atom_count_;
-  boost::filesystem::ifstream infile_;
-  boost::iostreams::filtering_stream<boost::iostreams::input>  in_;
-};
-
-class DLLEXPORT_OST_IO EntityIOMAEHandler: public EntityIOHandler {
-public:
-  virtual void Import(mol::EntityHandle& ent, const boost::filesystem::path& loc);
-  
-  virtual void Export(const mol::EntityView& ent, 
-                      const boost::filesystem::path& loc) const;
-                      
-  virtual void Import(mol::EntityHandle& ent, std::istream& stream);
-
-  virtual void Export(const mol::EntityView& ent, std::ostream& stream) const;
-  
-  static bool ProvidesImport(const boost::filesystem::path& loc, 
-                             const String& format="auto");
-  static bool ProvidesExport(const boost::filesystem::path& loc, 
-                             const String& format="auto");
-  virtual bool RequiresBuilder() const;
-
-  static String GetFormatName() { return String("Mae"); }
-  static String GetFormatDescription() { return String("MAEstro coordinate file format"); }
-};
-
-
 typedef EntityIOHandlerFactory<EntityIOMAEHandler> EntityIOMAEHandlerFactory;
 
 mol::EntityHandle DLLEXPORT_OST_IO LoadMAE(const String& file_name);
-- 
GitLab