Exemplo n.º 1
0
    def attach(self, object, attachname, desc=''):
        """
        Attach an object to this replica. This will create a pickle of the object
        with a temporary filename and store the pickle file name with a *name* and *description*
        in current replica attribute :attr:`Replica.attached` dictionary.

        :arg any object: Object to pickle and link to the replica
        :arg str attachname: Name to assign to the attachment
        :arg str desc: Description. Optional.
        """
        # Go to replica folder if not there
        T.BROWSER.gotoReplica(self)
        # If attachname present, remove it first
        if self.attached.has_key(attachname): self.dettach(attachname)

        # Obtain temp name, save pickle and store info in self.attached
        attachfile = fname = os.path.basename(
            tempfile.mktemp(prefix=self.name + '_%s_' % attachname))
        T.dump(object, attachfile)
        self.attached[attachname] = {'file': attachfile, 'desc': desc}

        if self.__folderscreated: self.write()

        # Goback to previous folder
        T.BROWSER.goback()
Exemplo n.º 2
0
    def test_AmberCrdParser(self):
        """AmberCrdParser test"""

        self.p = AmberCrdParser(self.finp,
                                self.fref,
                                box=True,
                                rnAmber=True,
                                log=self.log,
                                verbose=self.local)
        self.t = self.p.crd2traj()

        self.t.removeAtoms(
            lambda a: a['residue_name'] in ['WAT', 'Na+', 'Cl-'])
        self.t.removeAtoms(lambda a: a['element'] == 'H')

        if self.local:
            print "Dumping result to ", self.fout

        T.dump(self.t, T.absfile(self.fout))

        if self.local:
            print "Dumped Trajectory with %i frames and %i atoms." % \
                  (len(self.t), self.t.lenAtoms() )

        self.assertEqual(len(self.t), 10)
        self.assertEqual(self.t.lenAtoms(), 440)
Exemplo n.º 3
0
 def write(self):
     "Save object __dict__ to pickled file."
     self.log.debug("Writing pickle")
     with FileLock(self.replFilePath) as lock:
         d = self.__dict__.copy()
         del d['log']
         del d['grids']
         T.dump(d, self.replFilePath)
Exemplo n.º 4
0
 def write(self):
     "Save object __dict__ to pickled file."
     with FileLock(self.projFilePath) as lock:
         d = self.__dict__.copy()
         del d['log']
         d['systems'] = {}  # Empty systems and replicas
         d['replicas'] = {}
         T.dump(d, self.projFilePath)
Exemplo n.º 5
0
 def write(self, outfile=None):
     "Save object __dict__ to pickled file."
     outfile = outfile or self.sysFilePath
     with FileLock(outfile) as lock:
         d = self.__dict__.copy()
         d['create'] = None  #Dont pickle Amber class if loaded
         #            del d['log']
         T.dump(d, outfile)
         self.sysFilePath = osp.abspath(outfile)
         self.__sysfile = True
Exemplo n.º 6
0
 def saveSolvent(self, solvent, db=None, createEmpty=False):
     """
     Save a Solvent isntance in the database :attr:`db` or default DB locations.
     Selection of database is done in :meth:`self.__getDatabase`.
     
     :arg solvent: Solvent object to save.
     :type solvent: :class:`Solvent`
     :arg str db:        Database where to save the solvent.
                     If None, default ones will be used (package DB if
                     the user can write there, or user DB otherwise).
     :arg bool createEmpty:   If new database, create empty.
                         If False, copy data from package DB to the new DB.
     """
     db = self.__getDatabase(db, createEmpty)
     solvLib = T.load(db)
     solvLib[solvent.name] = solvent
     T.dump(solvLib, db)
     self.log.info("Solvent %s saved to database %s" % (solvent.name, db))
Exemplo n.º 7
0
    def __getDatabase(self, db=None, createEmpty=False):
        """
        Select and return database (which is actually a dictionary type) for which the user has writing permisions.
        By default, the package database will be used but if the user cannot write there,
        a new database will be created under the users home directory: $HOME/.mdmix/SOLVENTS.db
        which will also contain all solvents from the package db.

        :arg None|str db: If *db* != None:
                                - Check if this DB filename is writtable and return full path. Create it otherwise.
                            If None:
                                - Check if user has writing permisions in package DB and return the path.
                                - If not, create a user-spacific database and return the path.
        :arg bool createEmpty:   If the database has to be created, ignore solvents from the package DB.
                            Will create an empty DB.

        :return: Path to a db for which the user should have writting permisions.
        :type: string
        """
        import shutil
        # Try to use specified db
        if db:
            if osp.exists(db) and T.filePermission(db)['WRITE']:
                return T.absfile(db)
            else:
                if createEmpty: T.dump({}, db)
                else: shutil.copy(S.SOLVENTDB, db)
                return T.absfile(db)
        else:
            # USE USER DATABASE IF IT EXISTS
            if osp.exists(S.USER_SOLVENT_DB):
                return T.absfile(S.USER_SOLVENT_DB)
            else:
                db = S.SOLVENTDB

        # Create USER DB from package if user cannot write to package directory
        if not T.filePermission(db)['WRITE']:
            # User cannot write to package DB so create a custom one
            if createEmpty: T.dump({}, S.USER_SOLVENT_DB)
            else:
                shutil.copy(db, S.USER_SOLVENT_DB
                            )  # Make a copy to user's home mdmix folder
            db = S.USER_SOLVENT_DB

        return T.absfile(db)
Exemplo n.º 8
0
    def removeSolvent(self, solvName, db=None):
        """
        Remove solvent from database
        Same as saveSolvent, :attr:`db` will be chosen automatically if None.

        :arg str solvName: Solvent name. 
        :arg str db: Database path. If None, automatically detect.

        :raises SolventManagerError: if *db* does not contain *solvName*.
        """
        solvents = self.listSolvents(db)
        if solvName in solvents:
            solvLib.pop(solvName)
            T.dump(solvLib, db)
            self.log.info("Removed solvent %s from database %s" %
                          (solvName, db))
            return True
        else:
            raise SolventManagerError, "DB %s does not contain solvent name %s" % (
                db, solvName)
Exemplo n.º 9
0
def tracking_request(string_from, string_to, DEBUG_MODE=False):
    gmaps = googlemaps.Client(key='API-ID-googlemaps')

    tools.dprint("from:"+string_from+" to:"+string_to, DEBUG_MODE)

    # Putting them into the calculator
    now = datetime.now()
    directions_result = gmaps.directions(string_from, string_to, mode="driving", departure_time=now)

    # dump
    tools.dump(directions_result, DEBUG_MODE)

    duration = directions_result[0]["legs"][0]["duration_in_traffic"]["text"]
    eta = directions_result[0]["legs"][0]["duration_in_traffic"]["value"]

    # debug trace
    tools.dprint(eta, DEBUG_MODE)

    # Outputting the result
    return (duration, eta)
Exemplo n.º 10
0
    def test_AmberCrdParser(self):
        """AmberCrdParser test"""
        
        self.p = AmberCrdParser( self.finp, self.fref, box=True, rnAmber=True,
                                 log=self.log, verbose=self.local )
        self.t = self.p.crd2traj()

        self.t.removeAtoms(lambda a: a['residue_name'] in ['WAT','Na+','Cl-'] )
        self.t.removeAtoms(lambda a: a['element'] == 'H' )

        if self.local:
            print "Dumping result to ", self.fout

        T.dump( self.t, T.absfile(self.fout) )

        if self.local:
            print "Dumped Trajectory with %i frames and %i atoms." % \
                  (len(self.t), self.t.lenAtoms() )

        self.assertEqual( len(self.t), 10 )
        self.assertEqual( self.t.lenAtoms(), 440 )
Exemplo n.º 11
0
import GNUScreen as sc
from ScreenSaver import ScreenSaver
import tools



if __name__=='__main__':
    session=sys.argv[1]
    showpid=sys.argv[2]
    reverse=sys.argv[3]
    sort=sys.argv[4]
    try:
        groupids=sys.argv[5:]
    except:
        groupids=[]
    if showpid=='0':
        showpid=False
    else:
        showpid=True
    if reverse=='0':
        reverse=True
    else:
        reverse=False
    if sort=='0':
        sort=False
    else:
        sort=True
    ss=ScreenSaver(session)
    tools.dump(ss,showpid,reverse,sort,groupids)

Exemplo n.º 12
0
 def dump(self, file):
     "Write pickle to file *file*"
     T.dump(self, file)
Exemplo n.º 13
0
import sys
import GNUScreen as sc
from ScreenSaver import ScreenSaver
import tools
import util

if __name__ == '__main__':
    session = (sys.argv)[1]
    showpid = (sys.argv)[2]
    reverse = (sys.argv)[3]
    sort = (sys.argv)[4]
    windows = util.expand_numbers_list((sys.argv)[5:])

    if showpid == '0':
        showpid = False
    else:
        showpid = True
    if reverse == '0':
        reverse = True
    else:
        reverse = False
    if sort == '0':
        sort = False
    else:
        sort = True
    ss = ScreenSaver(session)
    tools.dump(ss, tools.require_dumpscreen_window(session, True), showpid,
               reverse, sort, windows)
    tools.cleanup()
Exemplo n.º 14
0
import sys
import GNUScreen as sc
from ScreenSaver import ScreenSaver
import tools
import util 

if __name__ == '__main__':
    session = (sys.argv)[1]
    showpid = (sys.argv)[2]
    reverse = (sys.argv)[3]
    sort = (sys.argv)[4]
    windows = util.expand_numbers_list((sys.argv)[5:])

    if showpid == '0':
        showpid = False
    else:
        showpid = True
    if reverse == '0':
        reverse = True
    else:
        reverse = False
    if sort == '0':
        sort = False
    else:
        sort = True
    ss = ScreenSaver(session)
    tools.dump(ss, tools.require_dumpscreen_window(session, True),
               showpid, reverse, sort, windows)
    tools.cleanup()