예제 #1
0
파일: main.py 프로젝트: gmp007/abICS
def main():
    tomlfile = sys.argv[1] if len(sys.argv) > 1 else "input.toml"
    rxparams = RXParams.from_toml(tomlfile)
    nreplicas = rxparams.nreplicas
    nprocs_per_replica = rxparams.nprocs_per_replica

    kB = 8.6173e-5

    comm = RX_MPI_init(rxparams)

    # RXMC parameters
    # specify temperatures for each replica, number of steps, etc.
    kTstart = rxparams.kTstart
    kTend = rxparams.kTend
    kTs = kB * np.linspace(kTstart, kTend, nreplicas)

    # Set Lreload to True when restarting
    Lreload = rxparams.reload

    nsteps = rxparams.nsteps
    RXtrial_frequency = rxparams.RXtrial_frequency
    sample_frequency = rxparams.sample_frequency
    print_frequency = rxparams.print_frequency

    dftparams = DFTParams.from_toml(tomlfile)

    if dftparams.solver == 'vasp':
        solver = VASPSolver(dftparams.path)
    elif dftparams.solver == 'qe':
        solver = QESolver(dftparams.path)
    else:
        print('unknown solver: {}'.format(dftparams.solver))
        sys.exit(1)

    # model setup
    # we first choose a "model" defining how to perform energy calculations and trial steps
    # on the "configuration" defined below
    energy_calculator = runner(base_input_dir=dftparams.base_input_dir,
                               Solver=solver,
                               nprocs_per_solver=nprocs_per_replica,
                               comm=MPI.COMM_SELF,
                               perturb=dftparams.perturb,
                               solver_run_scheme=dftparams.solver_run_scheme)
    model = dft_latgas(energy_calculator, save_history=False)

    # defect sublattice setup

    configparams = DFTConfigParams.from_toml(tomlfile)

    spinel_config = defect_config(configparams)

    configs = []
    for i in range(nreplicas):
        configs.append(copy.deepcopy(spinel_config))

    obsparams = ObserverParams.from_toml(tomlfile)

    # RXMC calculation
    RXcalc = TemperatureRX_MPI(comm, CanonicalMonteCarlo, model, configs, kTs)
    if Lreload:
        RXcalc.reload()
    obs = RXcalc.run(
        nsteps,
        RXtrial_frequency,
        sample_frequency,
        print_frequency,
        observer=default_observer(comm, Lreload),
        subdirs=True,
    )

    if comm.Get_rank() == 0:
        print(obs)
예제 #2
0
    def test_input(self):
        tomlfile = os.path.join(self.datadir, "input.toml")
        DFTParams.from_toml(tomlfile)

        rxparams = RXParams.from_toml(tomlfile)
        self.assertEqual(rxparams.nreplicas, 2)
        self.assertEqual(rxparams.nprocs_per_replica, 1)
        self.assertEqual(rxparams.kTstart, 1000.0)
        self.assertEqual(rxparams.kTend, 1200.0)
        self.assertEqual(rxparams.nsteps, 2)
        self.assertEqual(rxparams.RXtrial_frequency, 3)
        self.assertEqual(rxparams.sample_frequency, 4)
        self.assertEqual(rxparams.print_frequency, 5)
        self.assertEqual(rxparams.seed, 12345)

        configparams = DFTConfigParams.from_toml(tomlfile)
        spinel_config = defect_config(configparams)

        cellsize = np.array([2, 1, 1])
        self.assertTrue((spinel_config.cellsize == cellsize).all())

        A = np.zeros((3, 3))
        A[0, 0] = 2.0
        A[1, 1] = 1.0
        A[2, 2] = 0.5
        B = cellsize * A
        invB = inv(B)

        self.assertTrue(np.allclose(B, spinel_config.supercell))

        r = np.zeros((5, 3))
        r[1, :] = [0.5, 0.5, 0.5]
        r[2, :] = [0.0, 0.5, 0.5]
        r[3, :] = [0.5, 0.0, 0.5]
        r[4, :] = [0.5, 0.5, 0.0]
        st = Structure(A, ["O", "O", "Se", "Se", "Se"], r)

        seldyns = np.array([
            [True, True, False],
            [True, True, False],
            [True, False, True],
            [True, False, True],
            [True, False, True],
            [True, False, True],
            [False, False, False],
            [False, False, False],
            [True, True, True],
            [True, True, True],
        ])

        self.assertTrue(spinel_config.base_structure.matches(st))
        self.assertTrue(
            (spinel_config.base_structure.site_properties["seldyn"] == seldyns
             ).all())

        gs = [
            group("Al", ["Al"], coords=[[[0.0, 0.0, 0.0]]]),
            group("OH", ["O", "H"],
                  coords=[[[0.0, 0.0, 0.0], [0.1, 0.1, 0.1]]]),
        ]

        for i in range(2):
            g = spinel_config.defect_sublattices[0].groups[i]
            self.assertEqual(gs[i].name, g.name)
            self.assertEqual(gs[i].species, g.species)
            self.assertEqual(gs[i].natoms, g.natoms)
            self.assertTrue(np.allclose(np.dot(gs[i].coords, invB), g.coords))