Пример #1
0
def test_pretrained_no_config():
    config_1 = copy.deepcopy(config)
    trainer = AtomsTrainer(config_1)
    trainer.train()
    trained_cpdir = trainer.cp_dir
    e_mae_1, f_mae_1 = get_metrics(trainer)

    trainer_2 = AtomsTrainer()
    trainer_2.load_pretrained(trained_cpdir)
    e_mae_2, f_mae_2 = get_metrics(trainer_2)

    assert e_mae_1 == e_mae_2, "configless - pretrained energy metrics inconsistent!"
    assert f_mae_1 == f_mae_2, "configless - pretrained force metrics inconsistent!"
Пример #2
0
        def train_and_combine(args_list):
            """
            method for training trainer on ensemble sets, then create neural net calc,
            returns trained calc
            """
            training_dataset = args_list[0]
            trainer = args_list[1]

            trainer.train(raw_data=training_dataset)
            check_path = trainer.cp_dir
            trainer = AtomsTrainer()
            trainer.load_pretrained(checkpoint_path=check_path)
            trainer_calc = trainer.get_calc()
            return trainer_calc
def test_pretrained():
    torch.set_num_threads(1)

    trainer = AtomsTrainer(config)
    trainer.train()
    trained_cpdir = trainer.cp_dir
    e_mae_1, f_mae_1 = get_metrics(trainer)

    config["optim"]["epochs"] = 100
    pretrained_trainer = AtomsTrainer(config)
    pretrained_trainer.load_pretrained(trained_cpdir)
    e_mae_2, f_mae_2 = get_metrics(pretrained_trainer)

    assert e_mae_1 == e_mae_2, "Pretrained energy metrics inconsistent!"
    assert f_mae_1 == f_mae_2, "Pretrained force metrics inconsistent!"

    pretrained_trainer.train()
    e_mae_3, f_mae_3 = get_metrics(pretrained_trainer)
    assert e_mae_3 < e_mae_2, "Retrained metrics are larger!"
    assert f_mae_3 < f_mae_2, "Retrained metrics are larger!"
Пример #4
0
MCSHs = MCSHs_dict[MCSHs_index]

MCSHs = {
    "MCSHs": MCSHs,
    "atom_gaussians": potential_files,
    "cutoff": cutoff_distance
}

elements = [
    'Pt', 'Al', 'V', 'Pd', 'Fe', 'Sn', 'Ge', 'Bi', 'Ir', 'Re', 'Cd', 'Cr',
    'Ag', 'Hf', 'Ru', 'Ti', 'Cs', 'Os', 'N', 'As', 'O', 'S', 'Mo', 'Ta', 'Zn',
    'Y', 'Mn', 'Na', 'Rh', 'Hg', 'C', 'Co', 'Nb', 'Sc', 'Sr', 'H', 'Au', 'Ga',
    'Tl', 'K', 'Se', 'B', 'Pb', 'Ca', 'Cl', 'Cu', 'Zr', 'Rb', 'P', 'W', 'Tc',
    'Te', 'Ni', 'Sb', 'Si', 'In'
]

trainer = AtomsTrainer()
trainer.load_pretrained(checkpoint_name, gpu2cpu=True)
trainer.config["dataset"]["save_fps"] = False

result_dirname = "./test_result_val_id/sigma{}_MCSH{}_nodes{}_layers{}_cutoff{}_numtraining{}_results".format(
    sigmas_index, MCSHs_index, num_nodes, num_layers, cutoff_distance,
    num_training)

test_mae = predict_data(trainer,
                        test_images,
                        set_index,
                        result_dirname=result_dirname,
                        image_type="test")
Пример #5
0
def load_trainer(checkpoint_path):
    trainer = AtomsTrainer()
    # loading the pretrained model
    trainer.load_pretrained(checkpoint_path)
    return trainer
Пример #6
0
        "batch_size": batch_size,
        "epochs": epochs,
        "loss": "mae",
    },
    "dataset": {
        "lmdb_path": lmdb_paths,
        "val_split": val_split,
        "val_split_mode": "inorder",
        "cache": "partial"
    },
    "cmd": {
        "debug": False,
        "run_dir": "./",
        "seed": 1,
        "identifier": "test",
        "verbose": True,
        # Weights and Biases used for logging - an account(free) is required
        "logger": False,
    },
}

trainer = AtomsTrainer(config)
if os.path.isdir(checkpoint_name):
    trainer.load_pretrained(checkpoint_name)
else:
    print(
        "**** WARNING: checkpoint not found: {} ****".format(checkpoint_name))
print("training")
trainer.train()
print("end training")
Пример #7
0
def calculate_energy(x0):
    OH_bond_length = x0[0] 
    bond_angle = x0[1]
    images = read("../data/water.traj", index=":")
    images = [images[0]]

    sigmas = np.logspace(np.log10(0.02), np.log10(1.0), num=5)
    MCSHs = {
        "MCSHs": {
            "0": {"groups": [1], "sigmas": sigmas},
            "1": {"groups": [1], "sigmas": sigmas},
            "2": {"groups": [1, 2], "sigmas": sigmas},
            "3": {"groups": [1, 2, 3], "sigmas": sigmas},
            "4": {"groups": [1, 2, 3, 4], "sigmas": sigmas},
            "5": {"groups": [1, 2, 3, 4, 5], "sigmas": sigmas},
            # "6": {"groups": [1, 2, 3, 4, 5, 6, 7], "sigmas": sigmas},
        },
        "atom_gaussians": {
            "H": "../MCSH_potentials/H_pseudodensity_2.g",
            "O": "../MCSH_potentials/O_pseudodensity_4.g",
        },
        "cutoff": 8,
    }


    elements = ["H", "O"]
    config = {
        "model": {"get_forces": True, "num_layers": 3, "num_nodes": 20},
        "optim": {
            "device": "cpu",
            "force_coefficient": 0.2,
            "lr": 1e-3,
            "batch_size": 8,
            "epochs": 500,
        },
        "dataset": {
            "raw_data": images,
            # "val_split": 0.1,
            "elements": elements,
            "fp_scheme": "mcsh",
            "fp_params": MCSHs,
            "save_fps": True,
        },
        "cmd": {
            "debug": False,
            "run_dir": "./",
            "seed": 1,
            "identifier": "test",
            "verbose": True,
            "logger": False,
        },
    }

    trainer = AtomsTrainer(config)

    # loading the pretrained model
    trainer.load_pretrained("../checkpoints/2021-03-22-14-02-20-test")

    calculator = AMPtorch(trainer)

    image = molecule('H2O')
    image.set_distance(0, 2, OH_bond_length, fix=0)
    image.set_angle(1, 0, 2, bond_angle)
    image.set_cell([10, 10, 10])
    image.center()
    image.set_calculator(calculator)

    return image.get_potential_energy()