Nojump matrix is now saved in data when trajectory dir is not writable

This commit is contained in:
sebastiankloth 2023-04-20 13:35:10 +02:00
parent 78f0b3d727
commit d89c903e5d
3 changed files with 24 additions and 21 deletions

View File

@ -11,7 +11,7 @@ from . import autosave
from . import reader from . import reader
from .logging import logger from .logging import logger
__version__ = '22.6' __version__ = '23.4'
def open(directory='', topology='*.tpr', trajectory='*.xtc', cached=False, def open(directory='', topology='*.tpr', trajectory='*.xtc', cached=False,

View File

@ -106,44 +106,47 @@ def is_writeable(fname):
def nojump_load_filename(reader): def nojump_load_filename(reader):
directory, fname = path.split(reader.filename) directory, fname = path.split(reader.filename)
fname = path.join(directory, '.{}.nojump.npz'.format(fname)) full_path = path.join(directory, '.{}.nojump.npz'.format(fname))
if not is_writeable(directory): if not is_writeable(directory):
fname_fallback = os.path.join( user_data_dir = os.path.join("/data/",
os.path.join(os.environ['HOME'], '.mdevaluate/nojump'), os.environ['HOME'].split("/")[-1])
full_path_fallback = os.path.join(
os.path.join(user_data_dir, '.mdevaluate/nojump'),
directory.lstrip('/'), directory.lstrip('/'),
'.{}.nojump.npz'.format(fname) '.{}.nojump.npz'.format(fname)
) )
if os.path.exists(fname_fallback): if os.path.exists(full_path_fallback):
return fname_fallback return full_path_fallback
if os.path.exists(fname) or is_writeable(directory): if os.path.exists(fname) or is_writeable(directory):
return fname return full_path
else: else:
fname = os.path.join( user_data_dir = os.path.join("/data/",
os.path.join(os.environ['HOME'], '.mdevaluate/nojump'), os.environ['HOME'].split("/")[-1])
full_path_fallback = os.path.join(
os.path.join(user_data_dir, '.mdevaluate/nojump'),
directory.lstrip('/'), directory.lstrip('/'),
'.{}.nojump.npz'.format(fname) '.{}.nojump.npz'.format(fname)
) )
logger.info('Saving nojump to {}, since original location is not writeable.'.format(fname)) return full_path
os.makedirs(os.path.dirname(fname), exist_ok=True)
return fname
def nojump_save_filename(reader): def nojump_save_filename(reader):
directory, fname = path.split(reader.filename) directory, fname = path.split(reader.filename)
fname = path.join(directory, '.{}.nojump.npz'.format(fname)) full_path = path.join(directory, '.{}.nojump.npz'.format(fname))
if is_writeable(directory): if is_writeable(directory):
return fname return full_path
else: else:
fname = os.path.join( user_data_dir = os.path.join("/data/",
os.path.join(os.environ['HOME'], '.mdevaluate/nojump'), os.environ['HOME'].split("/")[-1])
full_path_fallback = os.path.join(
os.path.join(user_data_dir, '.mdevaluate/nojump'),
directory.lstrip('/'), directory.lstrip('/'),
'.{}.nojump.npz'.format(fname) '.{}.nojump.npz'.format(fname)
) )
logger.info('Saving nojump to {}, since original location is not writeable.'.format(fname)) logger.info('Saving nojump to {}, since original location is not writeable.'.format(full_path_fallback))
os.makedirs(os.path.dirname(fname), exist_ok=True) os.makedirs(os.path.dirname(full_path_fallback), exist_ok=True)
return fname return full_path_fallback
CSR_ATTRS = ('data', 'indices', 'indptr') CSR_ATTRS = ('data', 'indices', 'indptr')
NOJUMP_MAGIC = 2016 NOJUMP_MAGIC = 2016

View File

@ -22,6 +22,6 @@ setup(
'index-xtc = mdevaluate.cli:run' 'index-xtc = mdevaluate.cli:run'
] ]
}, },
version='22.11', version='23.4',
requires=['numpy', 'scipy'], requires=['numpy', 'scipy'],
) )