"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"inp.set_vars(kptopt=1, \n",
" ngkpt=[2, 2, 2], \n",
" nshiftk=2, \n",
" shiftk=[0.0, 0.0, 0.0, 0.5, 0.5, 0.5] # 2 shifts in one list\n",
" )\n",
"\n",
"# It is possible to use strings but use them only for special cases such as:\n",
"inp[\"istwfk\"] = \"*1\"\n",
"inp"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"If you mistype the name of the variable, `AbinitInput` raises an error:"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"Cannot find variable `perl` in internal database.\n",
"If you think this is not a typo, use:\n",
"\n",
" input.set_spell_check(False)\n",
"\n",
"to disable spell checking. Perhaps the internal database is not in synch\n",
"with the Abinit version you are using. Please contact the AbiPy developers.\n"
]
}
],
"source": [
"try:\n",
" inp.set_vars(perl=0)\n",
"except Exception as exc:\n",
" print(exc)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n",
"The AbinitInput is a mutable object so changing it will aftect all the references\n",
"to the object. \n",
"See http://docs.python-guide.org/en/latest/writing/gotchas/ for further info\n",
"
"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"a dict: {'foo': 'bar', 'hello': 'world'}\n",
"b dict: {'foo': 'bar', 'hello': 'world'}\n",
"c dict: {'foo': 'bar'}\n"
]
}
],
"source": [
"a = {\"foo\": \"bar\"}\n",
"b = a \n",
"c = a.copy()\n",
"a[\"hello\"] = \"world\"\n",
"print(\"a dict:\", a)\n",
"print(\"b dict:\", b)\n",
"print(\"c dict:\", c)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Defining the crystalline structure\n",
"[[back to top](#top)]"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The `set_structure` method sets the value of the ABINIT variables:\n",
" \n",
" * acell\n",
" * rprim\n",
" * ntypat\n",
" * natom \n",
" * typat\n",
" * znucl\n",
" * xred\n",
" \n",
"It is always a good idea to set the structure immediately after the creation of `AbinitInput`\n",
"because several methods use this information to facilitate the specification of other variables.\n",
"For example, the `set_kpath` method uses the structure to generate the high-symmetry $k$-path for band structure calculations.\n",
"\n",
"\n",
"`typat` must be consistent with the list of pseudopotentials passed to `AbinitInput`\n",
"
"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Structure from dictionary:"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {},
"outputs": [],
"source": [
"structure = dict(\n",
" ntypat=1, \n",
" natom=2,\n",
" typat=[1, 1],\n",
" znucl=14,\n",
" acell=3*[10.217],\n",
" rprim=[[0.0, 0.5, 0.5], \n",
" [0.5, 0.0, 0.5],\n",
" [0.5, 0.5, 0.0]],\n",
" xred=[[0.0 , 0.0 , 0.0],\n",
" [0.25, 0.25, 0.25]]\n",
")\n",
"\n",
"inp = AbinitInput(structure, pseudos=abidata.pseudos(\"14si.pspnc\"))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Structure from file"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"From a CIF file:"
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"Full Formula (Si2)
Reduced Formula: Si
abc : 3.866975 3.866975 3.866975
angles: 60.000000 60.000000 60.000000
Sites (2)
# SP a b c
--- ---- ---- ---- ----
0 Si 0 0 0
1 Si 0.25 0.25 0.25"
],
"text/plain": [
"Structure Summary\n",
"Lattice\n",
" abc : 3.86697462 3.86697462 3.86697462\n",
" angles : 59.99999999999999 59.99999999999999 59.99999999999999\n",
" volume : 40.88829179346891\n",
" A : 3.3488982567096763 0.0 1.9334873100000005\n",
" B : 1.1162994189032256 3.1573715557642927 1.9334873100000005\n",
" C : 0.0 0.0 3.86697462\n",
"PeriodicSite: Si (0.0000, 0.0000, 0.0000) [0.0000, 0.0000, 0.0000]\n",
"PeriodicSite: Si (1.1163, 0.7893, 1.9335) [0.2500, 0.2500, 0.2500]"
]
},
"execution_count": 18,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"inp.set_structure(abidata.cif_file(\"si.cif\"))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"From a Netcdf file produced by ABINIT:"
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"Full Formula (Si2)
Reduced Formula: Si
abc : 3.866975 3.866975 3.866975
angles: 60.000000 60.000000 60.000000
Sites (2)
# SP a b c
--- ---- ---- ---- ----
0 Si 0 0 0
1 Si 0.25 0.25 0.25
Abinit Spacegroup: spgid: 227, num_spatial_symmetries: 48, has_timerev: True, symmorphic: True"
],
"text/plain": [
"Structure Summary\n",
"Lattice\n",
" abc : 3.866974635206483 3.8669746352113457 3.8669746351893135\n",
" angles : 60.00000000018848 60.00000000014687 60.000000000400874\n",
" volume : 40.88829227593338\n",
" A : 3.348898269883833 0.0 1.9334873175946568\n",
" B : 1.1162994232769716 3.157371568197199 1.9334873175946568\n",
" C : 0.0 0.0 3.8669746351893135\n",
"PeriodicSite: Si (0.0000, 0.0000, 0.0000) [0.0000, 0.0000, 0.0000]\n",
"PeriodicSite: Si (1.1163, 0.7893, 1.9335) [0.2500, 0.2500, 0.2500]"
]
},
"execution_count": 19,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"inp.set_structure(abidata.ref_file(\"si_scf_GSR.nc\"))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Supported formats include:\n",
"\n",
" * *CIF*\n",
" * *POSCAR/CONTCAR*\n",
" * *CHGCAR* \n",
" * *LOCPOT*\n",
" * *vasprun.xml*\n",
" * *CSSR* \n",
" * *ABINIT netcdf files* \n",
" * *pymatgen's JSON serialized structures*"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### From the Materials Project database:"
]
},
{
"cell_type": "code",
"execution_count": 20,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"Full Formula (Si2)
Reduced Formula: Si
abc : 3.866975 3.866975 3.866975
angles: 60.000000 60.000000 60.000000
Sites (2)
# SP a b c magmom
--- ---- ----- ----- ----- --------
0 Si 0.875 0.875 0.875 0
1 Si 0.125 0.125 0.125 0"
],
"text/plain": [
"Structure Summary\n",
"Lattice\n",
" abc : 3.866974622849504 3.866974623775052 3.86697462\n",
" angles : 60.000000032293386 60.00000002437586 60.0000000241681\n",
" volume : 40.888291888494884\n",
" A : 3.34889826 0.0 1.93348731\n",
" B : 1.11629942 3.15737156 1.93348731\n",
" C : 0.0 0.0 3.86697462\n",
"PeriodicSite: Si (3.9070, 2.7627, 6.7672) [0.8750, 0.8750, 0.8750]\n",
"PeriodicSite: Si (0.5581, 0.3947, 0.9667) [0.1250, 0.1250, 0.1250]"
]
},
"execution_count": 20,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# https://www.materialsproject.org/materials/mp-149/\n",
"inp.set_structure(abilab.Structure.from_mpid(\"mp-149\"))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Remember to set the `PMG_MAPI_KEY` in ~/.pmgrc.yaml as described \n",
"[here](http://pymatgen.org/usage.html#setting-the-pmg-mapi-key-in-the-config-file)."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Note that you can avoid the call to `set_structure` if the `structure` argument is passed to `AbiniInput`:"
]
},
{
"cell_type": "code",
"execution_count": 21,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"############################################################################################
# STRUCTURE
############################################################################################
natom 2
ntypat 1
typat 1 1
znucl 14
xred
0.0000000000 0.0000000000 0.0000000000
0.2500000000 0.2500000000 0.2500000000
acell 1.0 1.0 1.0
rprim
6.3285005272 0.0000000000 3.6537614829
2.1095001757 5.9665675167 3.6537614829
0.0000000000 0.0000000000 7.3075229659"
],
"text/plain": [
""
]
},
"execution_count": 21,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"AbinitInput(structure=abidata.cif_file(\"si.cif\"), pseudos=abidata.pseudos(\"14si.pspnc\"))"
]
},
{
"cell_type": "markdown",
"metadata": {
"toc-hr-collapsed": true
},
"source": [
"## Brillouin zone sampling\n",
"[[back to top](#top)]\n",
"\n",
"There are two different types of sampling of the BZ: homogeneous and high-symmetry k-path.\n",
"The later is mainly used for band structure calculations and requires the specification of: \n",
"\n",
" * kptopt\n",
" * kptbounds\n",
" * ndivsm\n",
" \n",
"whereas the homogeneous sampling is needed for all the calculations in which \n",
"we have to compute integrals in the Brillouin zone e.g. total energy calculations, DOS, etc.\n",
"The $k$-mesh is usually specified via:\n",
"\n",
" * ngkpt\n",
" * nshiftk\n",
" * shiftk"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Explicit $k$-mesh"
]
},
{
"cell_type": "code",
"execution_count": 22,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'ngkpt': (1, 2, 3),\n",
" 'kptopt': 1,\n",
" 'nshiftk': 2,\n",
" 'shiftk': array([[0. , 0. , 0. ],\n",
" [0.5, 0.5, 0.5]])}"
]
},
"execution_count": 22,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"inp = AbinitInput(structure=abidata.cif_file(\"si.cif\"), pseudos=abidata.pseudos(\"14si.pspnc\"))\n",
"\n",
"# Set ngkpt, shiftk explicitly \n",
"inp.set_kmesh(ngkpt=(1, 2, 3), shiftk=[0.0, 0.0, 0.0, 0.5, 0.5, 0.5])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Automatic $k$-mesh "
]
},
{
"cell_type": "code",
"execution_count": 23,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'ngkpt': array([4, 4, 4]),\n",
" 'kptopt': 1,\n",
" 'nshiftk': 4,\n",
" 'shiftk': array([[0.5, 0.5, 0.5],\n",
" [0.5, 0. , 0. ],\n",
" [0. , 0.5, 0. ],\n",
" [0. , 0. , 0.5]])}"
]
},
"execution_count": 23,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Define a homogeneous k-mesh. \n",
"# nksmall is the number of divisions to be used to sample the smallest lattice vector,\n",
"# shiftk is automatically selected from an internal database.\n",
"\n",
"inp.set_autokmesh(nksmall=4)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### High-symmetry $k$-path"
]
},
{
"cell_type": "code",
"execution_count": 24,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'kptbounds': array([[0. , 0. , 0. ],\n",
" [0.5 , 0. , 0.5 ],\n",
" [0.5 , 0.25 , 0.75 ],\n",
" [0.375, 0.375, 0.75 ],\n",
" [0. , 0. , 0. ],\n",
" [0.5 , 0.5 , 0.5 ],\n",
" [0.625, 0.25 , 0.625],\n",
" [0.5 , 0.25 , 0.75 ],\n",
" [0.5 , 0.5 , 0.5 ],\n",
" [0.375, 0.375, 0.75 ],\n",
" [0.625, 0.25 , 0.625],\n",
" [0.5 , 0. , 0.5 ]]), 'kptopt': -11, 'ndivsm': 10, 'iscf': -2}"
]
},
"execution_count": 24,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Generate a high-symmetry k-path (taken from an internal database)\n",
"# Ten points are used to sample the smallest segment, \n",
"# the other segments are sampled so that proportions are preserved.\n",
"# A warning is issued by pymatgen about the structure not being standard.\n",
"# Be aware that this might possibly affect the automatic labelling of the boundary k-points on the k-path.\n",
"# So, check carefully the k-point labels on the figures that are produced in such case.\n",
"\n",
"inp.set_kpath(ndivsm=10)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Utilities\n",
"[[back to top](#top)]\n",
"\n",
"Once the structure has been defined, one can compute the number of valence electrons with:"
]
},
{
"cell_type": "code",
"execution_count": 25,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"The number of valence electrons is: 8\n"
]
}
],
"source": [
"print(\"The number of valence electrons is: \", inp.num_valence_electrons)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"If we need to change a particular (scalar) variable to generate inputs for convergence studies:"
]
},
{
"cell_type": "code",
"execution_count": 26,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[2, 4]\n"
]
}
],
"source": [
"# When using a non-integer step, such as 0.1, the results will often not\n",
"# be consistent. It is better to use ``linspace`` for these cases.\n",
"# See also numpy.arange and numpy.linspace\n",
"\n",
"ecut_inps = inp.arange(\"ecut\", start=2, stop=5, step=2)\n",
"\n",
"print([i[\"ecut\"] for i in ecut_inps])"
]
},
{
"cell_type": "code",
"execution_count": 27,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[0.001, 0.002, 0.003]\n"
]
}
],
"source": [
"tsmear_inps = inp.linspace(\"tsmear\", start=0.001, stop=0.003, num=3)\n",
"print([i[\"tsmear\"] for i in tsmear_inps])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Invoking Abinit with AbinitInput\n",
"[[back to top](#top)]\n",
"\n",
"Once you have an `AbinitInput`, you can call Abinit to get useful information \n",
"or simply to validate the input file before running the calculation.\n",
"All the method that invoke Abinit starts with the `abi` prefix \n",
"followed by a verb e.g. `abiget` or `abivalidate`."
]
},
{
"cell_type": "code",
"execution_count": 28,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"src_file: m_chkinp.F90\n",
"src_line: 3736\n",
"mpi_rank: 0\n",
"message: |\n",
" Checking consistency of input data against itself gave 2 inconsistencies.\n",
" The details of the problems can be found above.\n",
"...\n",
"\n",
"\n",
" abi_abort: decision taken to exit ...\n",
"\n"
]
}
],
"source": [
"inp = AbinitInput(structure=abidata.cif_file(\"si.cif\"), pseudos=abidata.pseudos(\"14si.pspnc\"))\n",
"\n",
"inp.set_vars(ecut=-2)\n",
"inp.set_autokmesh(nksmall=4)\n",
"\n",
"v = inp.abivalidate() \n",
"if v.retcode != 0: \n",
" # If there is a mistake in the input, one can acces the log file of the run with the log_file object\n",
" print(\"\".join(v.log_file.readlines()[-10:]))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Let's fix the problem with the negative ecut and rerun abivalidate!"
]
},
{
"cell_type": "code",
"execution_count": 29,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"All ok\n"
]
}
],
"source": [
"inp[\"ecut\"] = 2\n",
"inp[\"toldfe\"] = 1e-10\n",
"v = inp.abivalidate()\n",
"if v.retcode == 0: \n",
" print(\"All ok\")\n",
"else:\n",
" print(v)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"At this point, we have a valid input file and we can get the k-points in the irreducible zone with:"
]
},
{
"cell_type": "code",
"execution_count": 30,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"number of k-points: 10\n",
"k-points: [[-0.125 -0.25 0. ]\n",
" [-0.125 0.5 0. ]\n",
" [-0.25 -0.375 0. ]\n",
" [-0.125 -0.375 0.125]\n",
" [-0.125 0.25 0. ]\n",
" [-0.25 0.375 0. ]\n",
" [-0.375 0.5 0. ]\n",
" [-0.25 0.5 0.125]\n",
" [-0.125 0. 0. ]\n",
" [-0.375 0. 0. ]]\n",
"weights: [0.09375 0.09375 0.09375 0.1875 0.09375 0.09375 0.09375 0.1875 0.03125\n",
" 0.03125]\n",
"weights are normalized to: 1.0\n"
]
}
],
"source": [
"ibz = inp.abiget_ibz()\n",
"print(\"number of k-points:\", len(ibz.points))\n",
"print(\"k-points:\", ibz.points)\n",
"print(\"weights:\", ibz.weights)\n",
"print(\"weights are normalized to:\", ibz.weights.sum())"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We can also call the Abinit spacegroup finder with:"
]
},
{
"cell_type": "code",
"execution_count": 31,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"spacegroup found by Abinit: spgid: 227, num_spatial_symmetries: 48, has_timerev: True, symmorphic: True\n"
]
}
],
"source": [
"abistruct = inp.abiget_spacegroup()\n",
"print(\"spacegroup found by Abinit:\", abistruct.abi_spacegroup)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"To get the list of possible parallel configurations for this input up to 5 max_ncpus"
]
},
{
"cell_type": "code",
"execution_count": 32,
"metadata": {},
"outputs": [],
"source": [
"inp[\"paral_kgb\"] = 1\n",
"pconfs = inp.abiget_autoparal_pconfs(max_ncpus=5)"
]
},
{
"cell_type": "code",
"execution_count": 33,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"best efficiency:\n",
" {'efficiency': 0.8525,\n",
" 'mem_per_cpu': 0.0,\n",
" 'mpi_ncpus': 5,\n",
" 'omp_ncpus': 1,\n",
" 'tot_ncpus': 5,\n",
" 'vars': {'bandpp': 1,\n",
" 'npband': 1,\n",
" 'npfft': 1,\n",
" 'npimage': 1,\n",
" 'npkpt': 5,\n",
" 'npspinor': 1}}\n",
"\n",
"best speedup:\n",
" {'efficiency': 0.8525,\n",
" 'mem_per_cpu': 0.0,\n",
" 'mpi_ncpus': 5,\n",
" 'omp_ncpus': 1,\n",
" 'tot_ncpus': 5,\n",
" 'vars': {'bandpp': 1,\n",
" 'npband': 1,\n",
" 'npfft': 1,\n",
" 'npimage': 1,\n",
" 'npkpt': 5,\n",
" 'npspinor': 1}}\n",
"\n"
]
}
],
"source": [
"print(\"best efficiency:\\n\", pconfs.sort_by_efficiency()[0])\n",
"print(\"best speedup:\\n\", pconfs.sort_by_speedup()[0])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"To get the list of irreducible phonon perturbations at Gamma (Abinit notation)"
]
},
{
"cell_type": "code",
"execution_count": 34,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[{'qpt': [0.0, 0.0, 0.0], 'ipert': 1, 'idir': 1}]"
]
},
"execution_count": 34,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"inp.abiget_irred_phperts(qpt=(0, 0, 0))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Multiple datasets\n",
"[[back to top](#top)]\n",
"\n",
"Multiple datasets are handy when you have to generate several input files sharing several common\n",
"variables e.g. the crystalline structure, the value of ecut etc...\n",
"In this case, one can use the `MultiDataset` object that is essentially \n",
"a list of `AbinitInput` objects. Note however that `Abipy` workflows do not support input files with more than one dataset."
]
},
{
"cell_type": "code",
"execution_count": 35,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"4\n",
"4\n"
]
}
],
"source": [
"# A MultiDataset object with two datasets (a.k.a. AbinitInput) \n",
"multi = abilab.MultiDataset(structure=abidata.cif_file(\"si.cif\"),\n",
" pseudos=\"14si.pspnc\", pseudo_dir=abidata.pseudo_dir, ndtset=2)\n",
"\n",
"# A MultiDataset is essentially a list of AbinitInput objects \n",
"# with handy methods to perform global modifications.\n",
"# i.e. changes that will affect all the inputs in the MultiDataset\n",
"# For example:\n",
"multi.set_vars(ecut=4)\n",
"\n",
"# is equivalent to\n",
"#\n",
"# for inp in multi: inp.set_vars(ecut=4)\n",
"#\n",
"# and indeed:\n",
"\n",
"for inp in multi: \n",
" print(inp[\"ecut\"])"
]
},
{
"cell_type": "code",
"execution_count": 36,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'ngkpt': [4, 4, 4], 'tsmear': 0.008}"
]
},
"execution_count": 36,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# To change the values in a particular dataset use:\n",
"multi[0].set_vars(ngkpt=[2,2,2], tsmear=0.004)\n",
"multi[1].set_vars(ngkpt=[4,4,4], tsmear=0.008)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"To build a table with the values of \"ngkpt\" and \"tsmear\":"
]
},
{
"cell_type": "code",
"execution_count": 37,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" ngkpt | \n",
" tsmear | \n",
"
\n",
" \n",
" \n",
" \n",
" dataset 0 | \n",
" [2, 2, 2] | \n",
" 0.004 | \n",
"
\n",
" \n",
" dataset 1 | \n",
" [4, 4, 4] | \n",
" 0.008 | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" ngkpt tsmear\n",
"dataset 0 [2, 2, 2] 0.004\n",
"dataset 1 [4, 4, 4] 0.008"
]
},
"execution_count": 37,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"multi.get_vars_dataframe(\"ngkpt\", \"tsmear\")"
]
},
{
"cell_type": "code",
"execution_count": 39,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"ndtset 2
############################################################################################
### Global Variables.
############################################################################################
ecut 4
############################################################################################
# STRUCTURE
############################################################################################
natom 2
ntypat 1
typat 1 1
znucl 14
xred
0.0000000000 0.0000000000 0.0000000000
0.2500000000 0.2500000000 0.2500000000
acell 1.0 1.0 1.0
rprim
6.3285005272 0.0000000000 3.6537614829
2.1095001757 5.9665675167 3.6537614829
0.0000000000 0.0000000000 7.3075229659
#################
### DATASET 1 ###
#################
############################################################################################
# SECTION: basic
############################################################################################
ngkpt1 2 2 2
############################################################################################
# SECTION: gstate
############################################################################################
tsmear1 0.004
#################
### DATASET 2 ###
#################
############################################################################################
# SECTION: basic
############################################################################################
ngkpt2 4 4 4
############################################################################################
# SECTION: gstate
############################################################################################
tsmear2 0.008
#<JSON>
#{
# "pseudos": [
# {
# "basename": "14si.pspnc",
# "type": "NcAbinitPseudo",
# "symbol": "Si",
# "Z": 14,
# "Z_val": 4.0,
# "l_max": 2,
# "md5": "3916b143991b1cfa1542b130be320e5e",
# "filepath": "/Users/gmatteo/git_repos/abipy/abipy/data/pseudos/14si.pspnc",
# "@module": "pymatgen.io.abinit.pseudos",
# "@class": "NcAbinitPseudo"
# }
# ]
#}
#</JSON>
"
],
"text/plain": [
""
]
},
"execution_count": 39,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"multi"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n",
"Remember that in python we start to count from zero hence the first dataset has index 0.\n",
"
"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Calling set_structure on `MultiDataset` will set the structure of the inputs:"
]
},
{
"cell_type": "code",
"execution_count": 40,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[Structure Summary\n",
"Lattice\n",
" abc : 3.86697462 3.86697462 3.86697462\n",
" angles : 59.99999999999999 59.99999999999999 59.99999999999999\n",
" volume : 40.88829179346891\n",
" A : 3.3488982567096763 0.0 1.9334873100000005\n",
" B : 1.1162994189032256 3.1573715557642927 1.9334873100000005\n",
" C : 0.0 0.0 3.86697462\n",
"PeriodicSite: Si (0.0000, 0.0000, 0.0000) [0.0000, 0.0000, 0.0000]\n",
"PeriodicSite: Si (1.1163, 0.7893, 1.9335) [0.2500, 0.2500, 0.2500], Structure Summary\n",
"Lattice\n",
" abc : 3.86697462 3.86697462 3.86697462\n",
" angles : 59.99999999999999 59.99999999999999 59.99999999999999\n",
" volume : 40.88829179346891\n",
" A : 3.3488982567096763 0.0 1.9334873100000005\n",
" B : 1.1162994189032256 3.1573715557642927 1.9334873100000005\n",
" C : 0.0 0.0 3.86697462\n",
"PeriodicSite: Si (0.0000, 0.0000, 0.0000) [0.0000, 0.0000, 0.0000]\n",
"PeriodicSite: Si (1.1163, 0.7893, 1.9335) [0.2500, 0.2500, 0.2500]]\n"
]
}
],
"source": [
"multi.set_structure(abidata.cif_file(\"si.cif\"))\n",
"\n",
"# The structure attribute of a MultiDataset returns a list of structures \n",
"# equivalent to [inp.structure for inp in multi]\n",
"print(multi.structure)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The function `split_datasets` return the list of `AbinitInput` stored in MultiDataset"
]
},
{
"cell_type": "code",
"execution_count": 41,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"############################################################################################
# SECTION: basic
############################################################################################
ecut 4
ngkpt 2 2 2
############################################################################################
# SECTION: gstate
############################################################################################
tsmear 0.004
############################################################################################
# STRUCTURE
############################################################################################
natom 2
ntypat 1
typat 1 1
znucl 14
xred
0.0000000000 0.0000000000 0.0000000000
0.2500000000 0.2500000000 0.2500000000
acell 1.0 1.0 1.0
rprim
6.3285005272 0.0000000000 3.6537614829
2.1095001757 5.9665675167 3.6537614829
0.0000000000 0.0000000000 7.3075229659"
],
"text/plain": [
""
]
},
"execution_count": 41,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"inp0, inp1 = multi.split_datasets()\n",
"inp0"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n",
"You can use `MultiDataset` to build your input files but remember that \n",
"`Abipy` workflows will never support input files with more than one dataset.\n",
"As a consequence, you should always pass an `AbinitInput` to the \n",
"AbiPy functions that are building `Tasks`, `Works` or `Flows`.\n",
"
"
]
},
{
"cell_type": "code",
"execution_count": 42,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Number of datasets: 2\n"
]
}
],
"source": [
"print(\"Number of datasets:\", multi.ndtset)"
]
},
{
"cell_type": "code",
"execution_count": 43,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Now multi has 3 datasets and the ecut in the last dataset is: 42\n"
]
}
],
"source": [
"# To create and append a new dataset (initialized from dataset number 1)\n",
"multi.addnew_from(1)\n",
"multi[-1].set_vars(ecut=42)\n",
"print(\"Now multi has\", multi.ndtset, \"datasets and the ecut in the last dataset is:\", \n",
" multi[-1][\"ecut\"])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Back to the main [Index](index.ipynb)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.0"
},
"latex_envs": {
"bibliofile": "biblio.bib",
"cite_by": "apalike",
"current_citInitial": 1,
"eqLabelWithNumbers": true,
"eqNumInitial": 0
}
},
"nbformat": 4,
"nbformat_minor": 4
}