#!/usr/bin/env python
# coding: utf-8
from matador.scrapers import castep_scrapers
from matador.export import doc2res
from matador.utils.cell_utils import cart2abc
from matador.utils.print_utils import print_notify, print_success, print_failure
from sys import argv

fnames = argv[1:]
for fname in fnames:
    print_notify("Reading " + fname)
    cell_dict, success = castep_scrapers.cell2dict(
        fname, db=False, outcell=True, positions=True
    )
    cell_dict["lattice_abc"] = cart2abc(cell_dict["lattice_cart"])
    cell_dict["num_atoms"] = len(cell_dict["atom_types"])
    if success:
        doc2res(
            cell_dict,
            fname.replace(".cell", ""),
            hash_dupe=True,
            info=False,
            spoof_titl=True,
        )
        print_success("Wrote .res file to " + fname.replace(".cell", "") + ".res")
    else:
        print_failure("Unable to find final structure in " + fname + ".")
print_success("Completed!")
