diff --git a/modules/gui/pymod/export_file_loader.cc b/modules/gui/pymod/export_file_loader.cc index 3cd27c6edf6b6cc355edff91b1989a5bbe883b6b..5e006fb2cea35df25a72e46dfe6c2c3850a55216 100644 --- a/modules/gui/pymod/export_file_loader.cc +++ b/modules/gui/pymod/export_file_loader.cc @@ -31,16 +31,31 @@ using namespace ost::gui; namespace { -void load_object(const QString& file_name) +void load_object_a(const QString& file_name) { FileLoader::LoadObject(file_name); } -void load_from_site(const QString& id, const QString& site) +void load_object_b(const QString& file_name, const QString& selection) +{ + FileLoader::LoadObject(file_name, selection); +} + +void load_from_site_a(const QString& id) +{ + FileLoader::LoadFrom(id); +} + +void load_from_site_b(const QString& id, const QString& site) { FileLoader::LoadFrom(id,site); } +void load_from_site_c(const QString& id, const QString& site, const QString& selection) +{ + FileLoader::LoadFrom(id,site,selection); +} + void add_remote_site_loader(LoaderManager* loader_manager, const QString& site, RemoteSiteLoader* site_loader){ loader_manager->AddRemoteSiteLoader(site,site_loader); } @@ -56,11 +71,12 @@ void export_FileLoader() ; class_<FileLoader, boost::noncopyable>("FileLoader", no_init) - .def("LoadObject", &FileLoader::LoadObject) - .def("LoadObject", &load_object) + .def("LoadObject", &load_object_a) + .def("LoadObject", &load_object_b) .staticmethod("LoadObject") - .def("LoadFrom", &FileLoader::LoadFrom) - .def("LoadFrom", &load_from_site) + .def("LoadFrom", &load_from_site_a) + .def("LoadFrom", &load_from_site_b) + .def("LoadFrom", &load_from_site_c) .staticmethod("LoadFrom") .def("GetSiteLoaderIdents", &FileLoader::GetSiteLoaderIdents) .staticmethod("GetSiteLoaderIdents") diff --git a/modules/gui/pymod/export_remote_site_loader.cc b/modules/gui/pymod/export_remote_site_loader.cc index 257e8d3feeae4f42ef39be2238117c508eae0f68..3446fd6c09425f7b98fed48dcc41efc6e63ee79c 100644 --- a/modules/gui/pymod/export_remote_site_loader.cc +++ b/modules/gui/pymod/export_remote_site_loader.cc @@ -37,8 +37,8 @@ struct WrappedRemoteSiteLoader : public RemoteSiteLoader RemoteSiteLoader(), self(p) { } - virtual void LoadById(const QString& id){ - return call_method<void, std::string>(self, "LoadById", id.toStdString()); + virtual void LoadById(const QString& id, const QString& selection=QString()){ + return call_method<void, std::string>(self, "LoadById", id.toStdString(), selection.toStdString()); } virtual QString GetRemoteSiteName(){ @@ -49,9 +49,9 @@ struct WrappedRemoteSiteLoader : public RemoteSiteLoader return call_method<bool>(self, "IsImg"); } - virtual QNetworkReply* ById(const QString& id){ + virtual QNetworkReply* ById(const QString& id, const QString& selection=QString()){ //This hackish code will be changed soon(er or later) - unsigned long addr=call_method<unsigned long, std::string>(self, "ByIdAddr", id.toStdString()); + unsigned long addr=call_method<unsigned long, std::string>(self, "ByIdAddr", id.toStdString(), selection.toStdString()); QNetworkReply* network_reply= reinterpret_cast<QNetworkReply*>(addr); if(network_reply){ return network_reply; diff --git a/modules/gui/pymod/scene/file_loader.py b/modules/gui/pymod/scene/file_loader.py index f39403c802a56d4228484d848b9d6899127d94df..105ec8910efb314ff93c0a7606a0c9618d509dea 100644 --- a/modules/gui/pymod/scene/file_loader.py +++ b/modules/gui/pymod/scene/file_loader.py @@ -33,25 +33,25 @@ class BaseRemoteLoader(gui.RemoteSiteLoader): self.downloads_=dict() QtCore.QObject.connect(self.networkmanager_, QtCore.SIGNAL("finished(QNetworkReply*)"), self.DownloadFinished) - def LoadById(self, id): - self.ById(id) + def LoadById(self, id, selection=""): + self.ById(id, selection) - def ById(self, id): + def ById(self, id, selection=""): file_name=self.GetFileName(id) file = QtCore.QFile(file_name) if(file.size()==0): url = QtCore.QUrl(self.GetUrl(id)) request = QtNetwork.QNetworkRequest(url) reply = self.networkmanager_.get(request) - self.downloads_[reply]=id + self.downloads_[reply]=[id,selection] return reply else: - gui.FileLoader.LoadObject(str(file_name)) + gui.FileLoader.LoadObject(str(file_name),str(selection)) return None #Hack for C++ (will be changed soon) - def ByIdAddr(self,id): - reply = self.ById(id) + def ByIdAddr(self,id,selection): + reply = self.ById(id,selection) if reply is not None: return sip.unwrapinstance(reply) return 0 @@ -69,7 +69,7 @@ class BaseRemoteLoader(gui.RemoteSiteLoader): pass def DownloadFinished(self, reply): - file_name=self.GetFileName(self.downloads_[reply]) + file_name=self.GetFileName(self.downloads_[reply][0]) file = QtCore.QFile(file_name) if(reply.error()!=QtNetwork.QNetworkReply.NoError or reply.bytesAvailable()==0): self.HandleError(reply.errorString()); @@ -79,8 +79,9 @@ class BaseRemoteLoader(gui.RemoteSiteLoader): if(file.open(QtCore.QIODevice.WriteOnly)): file.write(reply.readAll()); file.close(); + selection=self.downloads_[reply][1] del(self.downloads_[reply]) - gui.FileLoader.LoadObject(str(file_name)) + gui.FileLoader.LoadObject(str(file_name),str(selection)) class GenericLoader(BaseRemoteLoader): EXT_NAME_ATTRIBUTE_NAME = "ExtName" diff --git a/modules/gui/src/file_loader.cc b/modules/gui/src/file_loader.cc index f768b0b4f93548589d5dc2e7c22fd5a08e87c98f..eab3697c59d2b9f757f17f8d06a8dd3e31ff44be 100644 --- a/modules/gui/src/file_loader.cc +++ b/modules/gui/src/file_loader.cc @@ -64,7 +64,7 @@ LoaderManagerPtr FileLoader::loader_manager_ = LoaderManagerPtr(); FileLoader::FileLoader(){} -void FileLoader::LoadObject(const QString& filename) +void FileLoader::LoadObject(const QString& filename, const QString& selection) { gfx::GfxObjP obj; if(filename.endsWith(".py",Qt::CaseInsensitive)){ @@ -74,11 +74,11 @@ void FileLoader::LoadObject(const QString& filename) filename.endsWith(".ent",Qt::CaseInsensitive)|| filename.endsWith(".pdb.gz",Qt::CaseInsensitive)|| filename.endsWith(".ent.gz",Qt::CaseInsensitive)){ - FileLoader::LoadPDB(filename); + FileLoader::LoadPDB(filename, selection); } else{ try{ - obj=FileLoader::TryLoadEntity(filename); + obj=FileLoader::TryLoadEntity(filename, io::EntityIOHandlerP(), selection); #if OST_IMG_ENABLED if (!obj) { try{ @@ -136,18 +136,18 @@ gfx::GfxObjP FileLoader::NoHandlerFound(const QString& filename) return gfx::GfxObjP(); } -void FileLoader::LoadFrom(const QString& id, const QString& site) +void FileLoader::LoadFrom(const QString& id, const QString& site, const QString& selection) { if(!loader_manager_) loader_manager_ = LoaderManagerPtr(new LoaderManager()); RemoteSiteLoader* remote_site = loader_manager_->GetRemoteSiteLoader(site); if(remote_site){ - remote_site->LoadById(id); + remote_site->LoadById(id,selection); } else{ remote_site = loader_manager_->GetCurrentSiteLoader(); if(remote_site){ - remote_site->LoadById(id); + remote_site->LoadById(id,selection); } } } @@ -201,7 +201,7 @@ void FileLoader::HandleError(Message m, ErrorType type, const QString& filename, } } -gfx::GfxObjP FileLoader::TryLoadEntity(const QString& filename, io::EntityIOHandlerP handler) throw (io::IOException) +gfx::GfxObjP FileLoader::TryLoadEntity(const QString& filename, io::EntityIOHandlerP handler, const QString& selection) throw (io::IOException) { if(!handler){ try{ @@ -213,7 +213,7 @@ gfx::GfxObjP FileLoader::TryLoadEntity(const QString& filename, io::EntityIOHand } if(handler){ if(dynamic_cast<io::EntityIOPDBHandler*>(handler.get())){ - FileLoader::LoadPDB(filename); + FileLoader::LoadPDB(filename, selection); } else{ QFileInfo file_info(filename); @@ -224,7 +224,7 @@ gfx::GfxObjP FileLoader::TryLoadEntity(const QString& filename, io::EntityIOHand conop::BuilderP builder = conop::Conopology::Instance().GetBuilder(); conop::Conopology::Instance().ConnectAll(builder,eh,0); } - gfx::GfxObjP obj(new gfx::Entity(file_info.baseName().toStdString(),eh)); + gfx::GfxObjP obj(new gfx::Entity(file_info.baseName().toStdString(),eh,mol::Query(selection.toStdString()))); return obj; } } @@ -305,7 +305,7 @@ void FileLoader::RunScript(const QString& filename) //HackerMode Off } -void FileLoader::LoadPDB(const QString& filename) +void FileLoader::LoadPDB(const QString& filename, const QString& selection) { io::PDBReader reader(filename.toStdString()); QList<mol::EntityHandle> entities; @@ -319,7 +319,7 @@ void FileLoader::LoadPDB(const QString& filename) QFileInfo file_info(filename); if(entities.size()==1){ - gfx::EntityP gfx_ent(new gfx::Entity(file_info.baseName().toStdString(),entities.first())); + gfx::EntityP gfx_ent(new gfx::Entity(file_info.baseName().toStdString(),entities.first(),mol::Query(selection.toStdString()))); try{ gfx::Scene::Instance().Add(gfx_ent); } @@ -333,7 +333,7 @@ void FileLoader::LoadPDB(const QString& filename) else{ try{ for(int i = 0 ; i<entities.size(); i++){ - gfx::EntityP gfx_ent(new gfx::Entity(QString(file_info.baseName()+" ("+QString::number(i)+")").toStdString(),entities[i])); + gfx::EntityP gfx_ent(new gfx::Entity(QString(file_info.baseName()+" ("+QString::number(i)+")").toStdString(),entities[i],mol::Query(selection.toStdString()))); gfx::Scene::Instance().Add(gfx_ent); } } diff --git a/modules/gui/src/file_loader.hh b/modules/gui/src/file_loader.hh index aefd67589e439363d84c8d9eeb63c291336f6de1..b102e17f69e0a62df75e1078c64dd79459b277a9 100644 --- a/modules/gui/src/file_loader.hh +++ b/modules/gui/src/file_loader.hh @@ -49,13 +49,13 @@ private: }; FileLoader(); - static gfx::GfxObjP TryLoadEntity(const QString& filename, io::EntityIOHandlerP handler=io::EntityIOHandlerP()) throw (io::IOException); + static gfx::GfxObjP TryLoadEntity(const QString& filename, io::EntityIOHandlerP handler=io::EntityIOHandlerP(), const QString& selection=QString()) throw (io::IOException); static gfx::GfxObjP TryLoadSurface(const QString& filename, io::SurfaceIOHandlerPtr handler=io::SurfaceIOHandlerPtr()) throw (io::IOException); #if OST_IMG_ENABLED static gfx::GfxObjP TryLoadMap(const QString& filename, io::MapIOHandlerPtr handler=io::MapIOHandlerPtr()) throw (io::IOException, io::IOFileAlreadyLoadedException); #endif static void RunScript(const QString& filename); - static void LoadPDB(const QString& filename); + static void LoadPDB(const QString& filename, const QString& selection=QString()); static void AddToScene(const QString& filename, gfx::GfxObjP obj); static void HandleError(Message m, ErrorType type, const QString& filename, gfx::GfxObjP obj=gfx::GfxObjP()); static gfx::GfxObjP NoHandlerFound(const QString& filename); @@ -68,8 +68,8 @@ private: #endif public: - static void LoadObject(const QString& filename); - static void LoadFrom(const QString& id, const QString& site=QString()); + static void LoadObject(const QString& filename, const QString& selection=QString()); + static void LoadFrom(const QString& id, const QString& site=QString(), const QString& selection=QString()); static std::vector<String> GetSiteLoaderIdents(); static LoaderManagerPtr GetLoaderManager(); }; diff --git a/modules/gui/src/remote_site_loader.cc b/modules/gui/src/remote_site_loader.cc index 8955715e0082d756433f2bf104226c4487d8d23e..26bd25cc50958655c5e58e791c9470b692fb7c90 100644 --- a/modules/gui/src/remote_site_loader.cc +++ b/modules/gui/src/remote_site_loader.cc @@ -21,8 +21,8 @@ namespace ost { namespace gui { RemoteSiteLoader::RemoteSiteLoader(){} - void RemoteSiteLoader::LoadById(const QString& id){this->ById(id);} - QNetworkReply* RemoteSiteLoader::ById(const QString& id){return NULL;} + void RemoteSiteLoader::LoadById(const QString& id, const QString& selection){this->ById(id,selection);} + QNetworkReply* RemoteSiteLoader::ById(const QString& id, const QString& selection){return NULL;} QString RemoteSiteLoader::GetRemoteSiteName(){return QString();} bool RemoteSiteLoader::IsImg() const { return false; } }} diff --git a/modules/gui/src/remote_site_loader.hh b/modules/gui/src/remote_site_loader.hh index cc4d7dc6cacfec548bbdbc5a704101f0cc34ffc4..648850fd5df57578311947545b487e2719ed389c 100644 --- a/modules/gui/src/remote_site_loader.hh +++ b/modules/gui/src/remote_site_loader.hh @@ -35,8 +35,8 @@ class DLLEXPORT_OST_GUI RemoteSiteLoader{ public: RemoteSiteLoader(); - virtual QNetworkReply* ById(const QString& id); - virtual void LoadById(const QString& id); + virtual QNetworkReply* ById(const QString& id, const QString& selection=QString()); + virtual void LoadById(const QString& id, const QString& selection=QString()); virtual QString GetRemoteSiteName(); virtual bool IsImg() const; virtual ~RemoteSiteLoader(){}; diff --git a/scripts/init.py b/scripts/init.py index 5032dc4b1eabd43ce9e3f562d9ee730b8fd202f7..f3549c69a6898944f6cafdb2f175972594c13e12 100644 --- a/scripts/init.py +++ b/scripts/init.py @@ -1,9 +1,8 @@ import __main__ -from ost import gui import sip import sys import optparse -from ost import io, mol, seq, geom, conop +from ost import io, mol, seq, geom, conop, gui import ost try: from ost import img @@ -61,93 +60,26 @@ def _InitFrontEnd(): _InitInspector() def _load_files(): - input_files=[_SplitIDSel(arg) for arg in loading_list] for pdb_id in options.pdb_ids: pdb_id, sel=_SplitIDSel(pdb_id) - GetModelFromPDB(pdb_id, '/tmp') - input_files.append(('/tmp/pdb%s.ent' % pdb_id, sel)) - index=0 - c=geom.Vec3() - graphical_objects=[] - try: - for f in input_files: - is_pdb_file=False - for ext in ['.pdb', '.ent', '.ent.gz', '.pdb.gz']: - if f[0].endswith(ext): - is_pdb_file=True - break - if is_pdb_file: - es=io.LoadPDB(f[0], load_multi=True) - for i, e in enumerate(es): - index+=1 - s=None - if len(options.query)>0: - if len(f[1])>0: - s=e.Select('(%s) and (%s)' % (options.query, f[1])) - else: - s=e.Select(options.query) - elif len(f[1])>0: - s=e.Select(f[1]) - else: - s=e - g=None - name=os.path.basename(f[0]) - if name.find('.')>-1: - name=name[:name.find('.')] - if len(es)>1: - name+=' (%d)' % i - g=gfx.Entity(name, s) - graphical_objects.append(g) - - gfx.Scene().Add(g) - c+=s.geometric_center - elif e=='.sdf': - index+=1 - e=io.LoadSDF(f[0]) - name=os.path.basename(f[0]) - if name.find('.')>-1: - name=name[:name.find('.')] - g=gfx.Entity(name, e) - graphical_objects.append(g) - gfx.Scene().Add(g) - c+=e.geometric_center - else: - if _img_present: - m=io.LoadMap(f[0]) - if m.GetExtent().GetDepth()==1: - images.append(m) - v=gui.CreateDataViewer(m) - viewers.append(v) - app=gui.GostyApp.Instance() - widget=gui.BPQtHandle(v.GetSipHandle()) - main_area=app.perspective.main_area - main_area.AddWidget(f[0], widget) - else: - stat=ost.img.alg.Stat() - m.Apply(stat) - miso=gfx.MapIso(os.path.basename(f[0]), m,stat.GetMean()) - c+=miso.center - graphical_objects.append(miso) - scene.Add(miso) - else: - raise Exception("unknown file type:"+f[0]) - step_size=0.0 - if len(input_files)>1: - step_size=1.0/(len(input_files)-1) - for i, go in enumerate(graphical_objects): - if hasattr(go, 'SetColor'): - if _img_present: - if type(go)==gfx.MapIso: - go.SetColor(gradient.GetColorAt(step_size*i)) - else: - go.SetColor(gradient.GetColorAt(step_size*i), 'aname=CA') - else: - go.SetColor(gradient.GetColorAt(step_size*i), 'aname=CA') - scene.center=c/index - except: - QtGui.QApplication.instance().exit() - raise -import __main__ + selection=_get_selection_query(sel) + gui.FileLoader.LoadFrom(pdb_id,"pdb.org",selection) + + input_files=[_SplitIDSel(arg) for arg in loading_list] + for f in input_files: + selection=_get_selection_query(f[1]) + gui.FileLoader.LoadObject(f[0],selection) + +def _get_selection_query(sel): + if len(options.query)>0: + if len(sel)>0: + return '(%s) and (%s)' % (options.query, sel) + else: + return options.query + elif len(sel)>0: + return sel + return "" + def _execute_script(): script=script_argv[0] sys_argv_backup=sys.argv @@ -168,37 +100,12 @@ def parse_script_option(option, opt, value, parser): script_argv.append(arg) del parser.rargs[0:len(parser.rargs)] -def GetModelFromPDB(model_id, output_dir, file_pattern='pdb%s.ent'): - conn=httplib.HTTPConnection('www.pdb.org') - print 'getting file for model with id=%s...' % model_id.lower() - conn.request('GET', '/pdb/files/%s.pdb' % model_id ) - response=conn.getresponse() - print response.reason - if response.status==200: - data=response.read() - f=open(os.path.join(output_dir, file_pattern % model_id), 'w+') - f.write(data) - f.close() - conn.close() - return True - conn.close() - return False - def _SplitIDSel(name): pos=name.find('[') if pos>-1: return name[:pos], name[pos+1:-1] return name, '' -# the nicest gradient the world has ever seen -gradient=gfx.Gradient() -gradient.SetColorAt(0.00, gfx.RED) -gradient.SetColorAt(0.25, gfx.GREY) -gradient.SetColorAt(0.50, gfx.LIGHTCYAN) -gradient.SetColorAt(0.75, gfx.YELLOW) -gradient.SetColorAt(1.00, gfx.DARKMAGENTA) - - loading_list=[] script_argv=[] images=[] @@ -251,4 +158,3 @@ if len(loading_list)!=0 or len(options.pdb_ids)!=0: if len(script_argv)!=0: _execute_script() -a=2