Skip to content

Commit 897b4d4

Browse files
committed
chore!: change --data-type into --chemical-space, args in functions as well
1 parent d680c33 commit 897b4d4

4 files changed

Lines changed: 28 additions & 28 deletions

File tree

rr_cache/Args.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
CONFIG_PATH = os_path.join(HERE, 'config')
1010
# Default values for the arguments
1111
DEFAULTS = {
12-
'data_type': 'mnx3.1',
12+
'cspace': 'mnx3.1',
1313
'interactive': False,
1414
'do_not_dwnl_cache': False,
1515
}
@@ -43,16 +43,17 @@ def add_arguments(parser: ArgumentParser) -> ArgumentParser:
4343
parser = add_logger_args(parser)
4444

4545
parser.add_argument(
46-
'--data-type',
47-
default=DEFAULTS['data_type'],
46+
'--chemical-space',
47+
dest='cspace',
48+
default=DEFAULTS['cspace'],
4849
type=str,
49-
help='Type of data to use (e.g. mnx3.1, mnx4.0...). Determines which configuration files and folders to use both the cache and the input cache (default: %(default)s).'
50+
help='chemical space to use (e.g. mnx3.1, mnx4.0...). Determines which configuration files and folders to use both the cache and the input cache (default: %(default)s).'
5051
)
5152
parser.add_argument(
52-
'--list-data-types',
53+
'--list-chemical-spaces',
5354
default=None,
5455
action='store_true',
55-
help='list available data types and exits'
56+
help='list available chemical spaces and exits'
5657
)
5758
parser.add_argument(
5859
'--build',

rr_cache/__main__.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,28 +76,28 @@ def entry_point():
7676

7777
logger = init(parser, args)
7878

79-
if args.list_data_types:
79+
if args.list_chemical_spaces:
8080
# list config_*.json files in CONFIG_PATH
8181
import os
8282
files = os.listdir(CONFIG_PATH)
83-
data_types = []
83+
cspaces = []
8484
for file in files:
8585
if file.startswith('config_') and file.endswith('.json'):
86-
data_types.append(file[len('config_'):-len('.json')])
86+
cspaces.append(file[len('config_'):-len('.json')])
8787
print(
88-
'{color}{typo}Available data types:{rst}{color}{rst}\n'.format(
88+
'{color}{typo}Available chemical spaces:{rst}{color}{rst}\n'.format(
8989
color=fg('white'),
9090
typo=attr('bold'),
9191
rst=attr('reset')
9292
)
9393
)
94-
for dt in data_types:
94+
for dt in cspaces:
9595
print(f'- {dt}')
9696
print()
9797
exit(0)
9898

9999
cache = rrCache(
100-
data_type=args.data_type,
100+
cspace=args.cspace,
101101
interactive=args.interactive,
102102
do_not_dwnl_cache=args.do_not_dwnl_cache,
103103
load=False,

rr_cache/rr_cache.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -87,15 +87,15 @@ class rrCache:
8787
## Cache constructor
8888
def __init__(
8989
self,
90-
data_type: str = DEFAULTS['data_type'],
90+
cspace: str = DEFAULTS['cspace'],
9191
interactive: bool = DEFAULTS['interactive'],
9292
do_not_dwnl_cache: bool = DEFAULTS['do_not_dwnl_cache'],
9393
load: bool = True,
9494
logger: Logger = getLogger(__name__)
9595
) -> 'rrCache':
9696
"""Constructor for the class
9797
Args:
98-
data_type (str): Version of MetaNetX to use.
98+
cspace (str): Chemical space to use (e.g. mnx3.1, mnx4.4...).
9999
interactive (bool): Whether to ask the user for confirmation before overwriting existing files.
100100
do_not_dwnl_cache (bool): Whether to download the cache files from the internet.
101101
load (bool): Whether to load the cache files into memory.
@@ -104,24 +104,24 @@ def __init__(
104104

105105
self.logger = logger
106106
self.logger.debug('New instance of rrCache')
107-
self.logger.debug('data_type: '+str(data_type))
107+
self.logger.debug('cspace: '+str(cspace))
108108
self.logger.debug('interactive: '+str(interactive))
109109
self.logger.debug('do_not_dwnl_cache: '+str(do_not_dwnl_cache))
110110
self.logger.debug('load: '+str(load))
111111

112-
self.__data_type = data_type
112+
self.__cspace = cspace
113113

114114
# Cache config
115115
cache_cfg_file = os_path.join(
116-
CONFIG_PATH, f'config_{self.__data_type}.json'
116+
CONFIG_PATH, f'config_{self.__cspace}.json'
117117
)
118118
try:
119119
with open(cache_cfg_file, 'r') as f:
120120
cache_cfg = json_load(f)
121121
rrCache.__cache_sources = cache_cfg['sources']
122122
rrCache.__cache = cache_cfg['cache']
123123
except FileNotFoundError:
124-
logger.error(f'Cache config file {cache_cfg_file} not found, please check the data_type argument')
124+
logger.error(f'Cache config file {cache_cfg_file} not found, please check the --chemical-space argument')
125125
logger.error('Exiting...')
126126
exit(1)
127127

@@ -137,9 +137,9 @@ def __init__(
137137
except FileNotFoundError:
138138
rrCache.__convertMNXM = {}
139139

140-
self.logger.info(f'Using {self.__data_type}')
141-
self.__input__cache_dir = os_path.join(HERE, 'input-cache', self.__data_type)
142-
self.__cache_dir = os_path.join(HERE, 'cache', self.__data_type)
140+
self.logger.info(f'Using {self.__cspace}')
141+
self.__input__cache_dir = os_path.join(HERE, 'input-cache', self.__cspace)
142+
self.__cache_dir = os_path.join(HERE, 'cache', self.__cspace)
143143
if load:
144144
self.Load(attrs=rrCache.__attributes_list, interactive=interactive, do_not_dwnl_cache=do_not_dwnl_cache)
145145

@@ -343,7 +343,6 @@ def Build(
343343
) -> None:
344344
"""Generate the cache files and store them to disk.
345345
Args:
346-
data_type (str): Version of MetaNetX to use.
347346
interactive (bool): Whether to ask the user for confirmation before overwriting existing files.
348347
logger (Logger): Logger instance for logging messages.
349348
"""

tests/test_rrCache.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@
2525

2626
class Test_rrCache(TestCase):
2727

28-
data_type = 'mnx3.1'
29-
outdir = f'cache-{data_type}'
30-
cache = rrCache(data_type=data_type, interactive=False)
28+
cspace = 'mnx3.1'
29+
outdir = f'cache-{cspace}'
30+
cache = rrCache(cspace=cspace, interactive=False)
3131

3232
# Not possible to compare hashes since
3333
# files contain dict that have to be sorted
@@ -44,7 +44,7 @@ def setUp(self, logger: Logger = None):
4444
with open(os_path.join(DATA_PATH, f'{elem}.json'), 'r') as f:
4545
setattr(self, f'{elem}', json_load(f))
4646
for elem in ['compounds', 'metrics']:
47-
with open(os_path.join(DATA_PATH, f'{elem}_{self.data_type}.json'), 'r') as f:
47+
with open(os_path.join(DATA_PATH, f'{elem}_{self.cspace}.json'), 'r') as f:
4848
setattr(self, f'{elem}', json_load(f))
4949

5050
def test_all_attr(self):
@@ -53,7 +53,7 @@ def test_all_attr(self):
5353
Method: Load a full rrCache in 'file' store mode. Then, for each
5454
attribute, compare its length with it is supposed to be.
5555
"""
56-
cache = rrCache(data_type=self.data_type, interactive=False, logger=self.logger)
56+
cache = rrCache(cspace=self.cspace, interactive=False, logger=self.logger)
5757
for attr in self.metrics:
5858
length = self.metrics[attr]['length']
5959
with self.subTest(attr=attr, length=length):
@@ -68,7 +68,7 @@ def test_single_attr_file(self):
6868
for attr in self.metrics:
6969
length = self.metrics[attr]['length']
7070
with self.subTest(attr=attr, length=length):
71-
cache = rrCache(data_type=self.data_type, interactive=False, logger=self.logger)
71+
cache = rrCache(cspace=self.cspace, interactive=False, logger=self.logger)
7272
self.assertEqual(len(cache.get(attr)), length)
7373

7474
def test_generate_cache(self):

0 commit comments

Comments
 (0)