Skip to content

Commit

Permalink
print failed names and closes file
Browse files Browse the repository at this point in the history
  • Loading branch information
BryTheGuy committed Mar 18, 2024
1 parent 8772800 commit dd4f6f9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
22 changes: 13 additions & 9 deletions GCMSpyDFT.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ def command_line():
help="silence output")

parser.add_argument('infile',
nargs='?',
# nargs='?',
type=argparse.FileType('r'),
default=sys.stdin,
# default=sys.stdin,
help="Input file name.")

parser.add_argument('-V',
Expand Down Expand Up @@ -219,6 +219,8 @@ def create_molecules(names: list[str], structures: list[str]) -> list[DataMolecu

def run() -> list[str]:
from config import cfg
warnings.simplefilter('error')

peak_blocks: list[list[str]] = read_input_file(args.infile) # collection of lines organized by peak

peak_list: list[object] = parse_peaks(peak_blocks) # collection of peak objects
Expand All @@ -231,23 +233,22 @@ def run() -> list[str]:
success_names: list[str] = []
data_molecule: list = [] # FIXME: rename

warnings.simplefilter('error')
for i, mol_name in enumerate(mol_names):
try:
structure = make_structure(mol_name)
mol_structures.append(structure)
success_names.append(mol_name)
logger.info(f'{cfg.OKCYAN}Success! {mol_name} is now a structure!{cfg.ENDC}')
logger.info(f'{cfg.OKCYAN} Success! {mol_name} is now a structure! {cfg.ENDC}')
# print(structure)
data_molecule.append((mol_name, structure, i))
except Warning as w:
failed_names.append(mol_name)
logger.warning(f'{cfg.FAIL}FAIL! {cfg.UNDERLINE}{mol_name}{cfg.SUNDERLINE} threw an error!\n'
f'{cfg.WARNING}{str(w).strip()}{cfg.ENDC}')
warnings.resetwarnings()
logger.warning(f'{cfg.FAIL} FAIL! {cfg.UNDERLINE}{mol_name}{cfg.SUNDERLINE} threw an error!\n'
f'{cfg.WARNING} {str(w).strip()} {cfg.ENDC}')

# mol_structures = make_structure(mol_names)
peak_molecules: list[DataMolecule] = create_molecules(mol_names, mol_structures)
peak_molecules: list[DataMolecule] = create_molecules(success_names, mol_structures)
# peak_molecules: list[DataMolecule] = create_molecules(*data_molecule)
for i, peak_molecule in enumerate(peak_molecules):
folder_path = (f'{cfg.output}/'
f'{getattr(peak, "peak_num")}'
Expand Down Expand Up @@ -282,6 +283,8 @@ def run() -> list[str]:
peak_molecule.mol.title = peak_molecule.name + ' ' + '/'.join(cfg.calc_type).strip() + ' GCMSpyDFT'

peak_molecule.mol.write(format='gau', filename=file_path, opt={'k': header + keywords}, overwrite=True)

warnings.resetwarnings()
return failed_names


Expand All @@ -296,4 +299,5 @@ def run() -> list[str]:
settings(args)
logger.info("Starting run")
if failed := run():
logger.error('List of molecules that failed to form structures.\n{0}'.format((name + '\n' for name in failed)))
logger.error(f'List of molecules that failed to form structures. {failed}')

1 change: 1 addition & 0 deletions interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ def read_to_list(input_file: TextIOWrapper) -> list:
# with open(input_file) as f:
# lines = f.read().splitlines()
lines = input_file.read().splitlines()
input_file.close()
return lines


Expand Down

0 comments on commit dd4f6f9

Please sign in to comment.