Commit 9e9c7fe1 authored by eric pellegrini's avatar eric pellegrini

Added new PDB examples

Improved the ClassRegistry import mechanism (avoid conflict with distro
module with the same name)
Improved the performance of the molecular viewer
Removed unused import
Bug fix in QVectors widgets
parent 88a4aae3
This diff is collapsed.
This diff is collapsed.
......@@ -32,6 +32,7 @@ Created on Mar 30, 2015
import abc
import glob
import imp
import inspect
import os
import sys
......@@ -112,7 +113,7 @@ class ClassRegistry(abc.ABCMeta):
'''
Update the classes registry by importing all the modules contained in a given package.
Only the classes that are metaclassed by ClassRegistry will be registered.
Only the classes metaclassed by :py:class:`~MDANSE.Core.ClassRegistry.ClassRegistry` will be registered.
:param packageDir: the package for which all modules should be imported
:type packageDir: str
......@@ -125,16 +126,22 @@ class ClassRegistry(abc.ABCMeta):
if moduleFile == '__init__.py':
continue
moduleName, moduleExt = os.path.splitext(moduleFile)
moduleName, _ = os.path.splitext(moduleFile)
if moduleDir not in sys.path:
sys.path.append(moduleDir)
# Any error that may occur here has to be caught. In such case the module is skipped.
try:
__import__(moduleName, locals(), globals())
filehandler,path,description = imp.find_module(moduleName, [moduleDir])
mod = imp.load_module(moduleName,filehandler,path,description)
except:
continue
else:
if not os.path.samefile(os.path.dirname(mod.__file__),moduleDir):
print "A module with name %s is already present in your distribution with %s path." % (moduleName,)
@classmethod
def info(cls, interface):
......
......@@ -32,7 +32,7 @@ Created on Mar 30, 2015
class Error(Exception):
'''
Base class for handling exception occuring in MDANSE.
Base class for handling exception occurring in MDANSE.
Any exception defined in MDANSE should derive from it in order to be properly handled
in the GUI application.
......
......@@ -39,7 +39,6 @@ import os
import re
import subprocess
import tempfile
import types
from MDANSE.Core.Error import Error
......
......@@ -56,7 +56,7 @@ class Configurable(object):
settings = collections.OrderedDict()
def __init__(self):
def __init__(self,settings=None):
'''
Constructor
'''
......@@ -65,6 +65,9 @@ class Configurable(object):
self._configured=False
if settings is not None:
self.settings = settings
self.build_configuration()
def build_configuration(self):
......
......@@ -66,11 +66,11 @@ class PDBConverter(Converter):
self.numberOfSteps = self.configuration['nb_frame']["number"]
# Create all objects from the PDB file.
pdb_config = PDBFile(self.configuration['pdb_file']['filename'], model = 0)
pdb_config = PDBFile(self.configuration['pdb_file']['filename'], model=0)
# Create the universe.
self._universe = pdb_config.createUnitCellUniverse()
# Construct system
self._universe.addObject(pdb_config.createAll(None, 1))
......@@ -95,7 +95,7 @@ class PDBConverter(Converter):
pdb_config = PDBFile(self.configuration['pdb_file']['filename'], model=frame)
uni = pdb_config.createUnitCellUniverse()
uni.addObject(pdb_config.createAll(None, 1))
univ_config = Configuration(self._universe, uni.configuration().array)
self._universe.setConfiguration(univ_config)
......
......@@ -106,6 +106,8 @@ class IJob(Configurable):
type = "job"
section = "job"
ancestor = 'molecular_viewer'
@staticmethod
def define_unique_name():
......@@ -294,7 +296,7 @@ class IJob(Configurable):
f.write('\n')
f.write('job = REGISTRY[%r][%r]()\n' % ('job',cls.type))
f.write('job.run(parameters,status=False)')
f.write('job.run(parameters,status=True)')
f.close()
......
......@@ -27,12 +27,13 @@
'''
Created on Apr 14, 2015
:author: Eric C. ellegrini
:author: Eric C. Pellegrini
'''
import os
import subprocess
import sys
import tempfile
import time
import wx
......@@ -40,8 +41,9 @@ import wx.aui as aui
from MDANSE import PLATFORM,REGISTRY
from MDANSE.Externals.pubsub import pub
from MDANSE.Framework.Plugins.ComponentPlugin import ComponentPlugin
from MDANSE.GUI import DATA_CONTROLLER
from MDANSE.GUI.WorkingPanel import WorkingPanel
from MDANSE.GUI.ComboWidgets.ConfigurationPanel import ConfigurationPanel
from MDANSE.GUI.ComboWidgets.JobHelpFrame import JobHelpFrame
......@@ -106,10 +108,11 @@ class JobPlugin(ComponentPlugin):
return
name = self._job.define_unique_name()
script = os.path.join(PLATFORM.jobscripts_directory(),name)+'.py'
self._job.save(script, parameters)
handle,filename = tempfile.mkstemp(prefix="MDANSE_%s.py" % name, text=True)
os.close(handle)
self._job.save(filename, parameters)
if PLATFORM.name == "windows":
startupinfo = subprocess.STARTUPINFO()
......@@ -118,7 +121,7 @@ class JobPlugin(ComponentPlugin):
else:
startupinfo = None
subprocess.Popen([sys.executable, script], startupinfo=startupinfo, stdin=subprocess.PIPE,stdout=subprocess.PIPE, stderr=subprocess.PIPE)
subprocess.Popen([sys.executable, filename], startupinfo=startupinfo, stdin=subprocess.PIPE,stdout=subprocess.PIPE, stderr=subprocess.PIPE)
time.sleep(1)
......@@ -159,7 +162,7 @@ class JobPlugin(ComponentPlugin):
class JobFrame(wx.Frame):
def __init__(self, parent, jobType, datakey):
def __init__(self, parent, jobType, datakey=None):
wx.Frame.__init__(self, parent, wx.ID_ANY, size = (800,400), style=wx.DEFAULT_DIALOG_STYLE|wx.MINIMIZE_BOX|wx.MAXIMIZE_BOX|wx.RESIZE_BORDER)
......@@ -167,9 +170,10 @@ class JobFrame(wx.Frame):
self._datakey = datakey
data = REGISTRY['input_data']['mmtk_trajectory'](self._datakey)
DATA_CONTROLLER[filename] = data
if self._datakey is not None:
data = REGISTRY['input_data']['mmtk_trajectory'](self._datakey)
DATA_CONTROLLER[filename] = data
self.build_dialog()
......@@ -196,13 +200,10 @@ class JobFrame(wx.Frame):
self.Destroy()
if __name__ == "__main__":
from MDANSE.GUI import DATA_CONTROLLER
from MDANSE.GUI.WorkingPanel import WorkingPanel
filename = os.path.join(os.path.dirname(PLATFORM.package_directory()),'Data','Trajectories','MMTK','protein_in_periodic_universe.nc')
app = wx.App(False)
f = JobFrame(None,'mvi',filename)
f = JobFrame(None,'msd',filename)
f.Show()
app.MainLoop()
\ No newline at end of file
......@@ -245,7 +245,7 @@ if __name__ == "__main__":
app = wx.App(False)
p = AtomsListDialog(None,t,3)
p = AtomsListDialog(None,t,10)
p.ShowModal()
......
......@@ -222,6 +222,7 @@ class QVectorsDialog(UserDefinitionsDialog):
return
self._ud['parameters'] = (qPanel.generator.type,qPanel.parameters)
self._ud['generator'] = qPanel.generator.type
self._ud['q_vectors'] = qPanel.grid.GetTable().data
self._ud['is_lattice'] = qPanel.generator.is_lattice
......
......@@ -47,7 +47,7 @@ class Logger(object):
def __call__(self,message,level="info",loggers=None):
lvl = Logger.levels.get(level,None)
# If the logging level is unkwnown, skip that log
if lvl is None:
return
......
......@@ -44,7 +44,8 @@ def build_connectivity(universe ,tolerance=0.05):
scannedObjects = [obj for obj in universe.objectList() if isinstance(obj,AtomCluster)]
singleAtomsObjects = [obj for obj in universe.objectList() if isinstance(obj,Atom) or obj.numberOfAtoms()==1]
scannedObjects.append(Collection(singleAtomsObjects))
if singleAtomsObjects:
scannedObjects.append(Collection(singleAtomsObjects))
for obj in scannedObjects:
......
......@@ -32,13 +32,13 @@ Created on Mar 26, 2015
from __pkginfo__ import __version__, __author__, __date__
from MDANSE.Logging.Logger import LOGGER
from MDANSE.Core.Platform import PLATFORM
from MDANSE.Core.ClassRegistry import ClassRegistry as REGISTRY
from MDANSE.Data.ElementsDatabase import ELEMENTS
from MDANSE.Logging.Logger import LOGGER
from MDANSE.Core.Preferences import PREFERENCES
import Framework
......
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