Skip to content
Snippets Groups Projects
Commit 8c7d5a10 authored by Simon Sebastian Humpohl's avatar Simon Sebastian Humpohl
Browse files

Initial commit

parents
Branches
No related tags found
No related merge requests found
.ipynb_checkpoints/
simulation_venv/
__pycache__
/.jupyter_ystore.db
/.virtual_documents/
%% Cell type:markdown id:136f209c-91a7-4a11-8386-ef5535eeba9a tags:
# Data generation
Create a virtual environment with the correct
%% Cell type:code id:e18e2f2d-e0da-43eb-b378-2b617dbb73fa tags:
``` python
import simulation
import numpy as np
materials = ['Au', 'Ag', 'Al', 'Cu', 'Ni']
lattice_constants = np.linspace(3.0, 4.5, 100)
```
%% Cell type:code id:eaa1b986-1329-491d-850f-4d5edefe5b14 tags:
``` python
emt_data = simulation.simulate_multi(
materials = materials,
lattice_constants = lattice_constants, # Ångstroms
calculator='EMT',
pool_size=None,
)
emt_data.to_netcdf('emt_data.ndf')
emt_df = emt_data.to_dataframe()
emt_df.to_csv('emt_data.csv')
```
%% Cell type:code id:36aac675-21f5-4c7b-b225-416c3681b0b8 tags:
``` python
lj_data = simulation.simulate_multi(
materials = materials,
lattice_constants = lattice_constants, # Ångstroms
calculator='LennardJones',
)
lj_data.to_netcdf('lj_data.ndf')
lj_df = lj_data.to_dataframe()
lj_df.to_csv('lj_data.csv')
```
%% Cell type:markdown id:f7a5a554-26ce-4695-aa37-c787df57268d tags:
# Data analysis
%% Cell type:code id:941fe208-519d-4c9f-ab6d-1d973181c66f tags:
``` python
```
%% Cell type:code id:028e3710-8ab2-44c6-809b-f7b1ae1a3e98 tags:
``` python
```
from multiprocessing import Pool as ProcessPool
import itertools
from typing import Literal
import numpy as np
import xarray as xr
from ase.build import bulk
from ase.calculators.emt import EMT
from ase.calculators.lj import LennardJones
CALCULATORS = {
# Effective Medium Theory
'EMT': EMT,
# LennardJones potential
'LennardJones': LennardJones,
}
def simulate_properties(material, lattice_constant, calculator: Literal['EMT', 'EAM']):
atoms = bulk(material, a=lattice_constant)
atoms.calc = CALCULATORS[calculator]()
return {
'Energy': atoms.get_potential_energy(),
'Volume': atoms.get_volume(),
}
def simulate_multi(materials, lattice_constants, calculator: Literal['EMT', 'EAM'] = 'EMT', pool_size=None):
arg_iter = ((material, lattice_constant, calculator) for (material, lattice_constant) in itertools.product(materials, lattice_constants))
with ProcessPool(pool_size) as pool:
results = pool.starmap(simulate_properties, arg_iter, chunksize=10)
shape = len(materials), len(lattice_constants)
energies, volumes = zip(*((result['Energy'], result['Volume']) for result in results))
return xr.Dataset(
{
"Energy": (("material", "lattice_constant"), np.array(energies).reshape(shape)),
"Volume": (("material", "lattice_constant"), np.array(volumes).reshape(shape)),
},
coords={
"lattice_constant": lattice_constants,
"material": materials,
}
)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment