Example #1
0
def main(args):

    eval_name = args.modelpath.split("/")[-1]
    eval_file = "evaluation_" + eval_name + ".txt"
    if os.path.exists(eval_file):
        if args.overwrite:
            os.remove(eval_file)
        else:
            raise Exception(
                "The evaluation file already exists. Delete it or add the overwrite flag."
            )
    device = "cuda" if args.cuda else "cpu"
    calculator = mlcalcdriver.calculators.SchnetPackCalculator(args.modelpath,
                                                               device=device)

    with connect(args.dbpath) as db:
        answers, results = (
            [[] for _ in range(len(args.properties))],
            [[] for _ in range(len(args.properties))],
        )
        posinp = []
        for row in db.select():
            for i, prop in enumerate(args.properties):
                answers[i].append(row.data[prop])
            posinp.append(Posinp.from_ase(row.toatoms()))

            if len(posinp) == args.batch_size:
                job = Job(posinp=posinp, calculator=calculator)
                for i, prop in enumerate(args.properties):
                    job.run(prop, batch_size=args.batch_size)
                    results[i].append(job.results[prop].tolist())
                posinp = []
        if len(posinp) > 0:
            job = Job(posinp=posinp, calculator=calculator)
            for i, prop in enumerate(args.properties):
                job.run(prop, batch_size=args.batch_size)
                results[i].append(job.results[prop])
            posinp = []

    header, error = [], []
    for prop in args.properties:
        header += ["MAE_" + prop, "%Error_" + prop, "RMSE_" + prop]
    for l1, l2 in zip(answers, results):
        an, re = np.array(l1).flatten(), np.concatenate(l2).flatten()
        error.append(np.abs(an - re).mean())
        error.append(np.abs((an - re) / an).mean() * 100)
        error.append(np.sqrt(np.mean((an - re)**2)))

    with open(eval_file, "w") as file:
        wr = csv.writer(file)
        wr.writerow(header)
        wr.writerow(error)
Example #2
0
 def test_periodic(self):
     pos1 = Posinp.from_file(os.path.join(pos_folder, "periodic.xyz"))
     atoms = posinp_to_ase_atoms(pos1)
     pos2 = Posinp.from_ase(atoms)
     assert pos1 == pos2
Example #3
0
 def test_surface(self):
     pos1 = Posinp.from_file(os.path.join(pos_folder, "surface2.xyz"))
     atoms = posinp_to_ase_atoms(pos1)
     pos2 = Posinp.from_ase(atoms)
     assert pos1 == pos2