import os
[docs]def add_atoms(atoms_list):
add = ''
sub = ''
for atoms in atoms_list:
if isinstance(atoms, float):
continue
if len(atoms) > 0 and atoms[0] == '-':
sub += atoms[1:]
else:
add += atoms
return add.replace(sub, '', 1)
[docs]def check_reaction(reactants, products):
"""Check the stoichiometry and format of chemical reaction used for
folder structure.
list of reactants -> list of products
"""
reactant_list = [reactant.split('@')[0].strip(
'star').strip('gas') for reactant in reactants]
product_list = [product.split('@')[0].strip(
'star').strip('gas') for product in products]
reactant_atoms = [extract_atoms(reactant) for reactant in reactant_list]
product_atoms = [extract_atoms(product) for product in product_list]
reactants = add_atoms(reactant_atoms)
products = add_atoms(product_atoms)
r_stars = 0
p_stars = 0
for i, a in enumerate(reactant_atoms):
if a == '' or 'star' in reactant_list[i]:
r_stars += 1
elif isinstance(a, float):
r_stars += a
for a in product_atoms:
if a == '':
p_stars += 1
elif isinstance(a, float):
p_stars += a
assert ''.join(sorted(reactants)) == ''.join(sorted(products))
[docs]def get_catbase():
if 'SHERLOCK' in os.environ:
sherlock = os.environ['SHERLOCK']
if sherlock == '1':
catbase = '/home/winther/data_catapp/'
elif sherlock == '2':
catbase = '/home/users/winther/data_catapp/'
elif 'SLAC_ENVIRON' in os.environ:
catbase = '/nfs/slac/g/suncatfs/data_catapp/'
else:
catbase = './'
return catbase
[docs]def get_bases(folder_name):
catbase = get_catbase()
if os.environ['USER'] == 'winther':
data_base = catbase + 'winther/databases/'
user = folder_name
else:
user = os.environ['USER']
data_base = catbase + folder_name + '/'
user_base = catbase + folder_name
return catbase, data_base, user, user_base