Spaces:
Building
Building
File size: 9,103 Bytes
5225959 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 |
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"id": "08ee4c09-7fb5-4ce1-a7a3-5c5c52a6d4d5",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"from ase import Atoms, Atom\n",
"from ase.io import read, write\n",
"from ase.data import chemical_symbols, covalent_radii, vdw_alvarez\n",
"from ase.parallel import paropen as open\n",
"from gpaw import GPAW, PW, FermiDirac, LCAO\n",
"from gpaw import Davidson\n",
"from gpaw import Mixer, MixerSum, MixerDif\n",
"from gpaw.directmin.etdm_lcao import LCAOETDM\n",
"from gpaw.cdft.cdft import CDFT\n",
"from pathlib import Path\n",
"import os\n",
"import numpy as np\n",
"from pymatgen.core import Element\n",
"from tqdm.auto import tqdm\n",
"import pandas as pd"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "90887faa-1601-4c4c-9c44-d16731471d7f",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"\n",
"magnetism = 'NM'\n",
"\n",
"for symbol in tqdm(chemical_symbols):\n",
" \n",
" s = set([symbol])\n",
" \n",
" if 'X' in s:\n",
" continue\n",
" \n",
" try:\n",
" atom = Atom(symbol)\n",
" rmin = covalent_radii[atom.number] * 2 * 0.6\n",
" rvdw = vdw_alvarez.vdw_radii[atom.number] if atom.number < len(vdw_alvarez.vdw_radii) else np.nan \n",
" rmax = 3.1 * rvdw if not np.isnan(rvdw) else 6\n",
" rstep = 0.2 #if rmin < 1 else 0.4\n",
"\n",
" a = 2 * rmax\n",
"\n",
" npts = int((rmax - rmin)/rstep)\n",
"\n",
" rs = np.linspace(rmin, rmax, npts)\n",
" e = np.zeros_like(rs)\n",
"\n",
" da = symbol + symbol\n",
"\n",
" out_dir = Path(str(da + f\"_{magnetism}\"))\n",
"\n",
" os.makedirs(out_dir, exist_ok=True)\n",
"\n",
" skip = 0\n",
" \n",
" element = Element(symbol)\n",
" \n",
" try:\n",
" m = element.valence[1]\n",
" if element.valence == (0, 2):\n",
" m = 0\n",
" except:\n",
" m = 0\n",
" \n",
" \n",
" r = rs[0]\n",
" \n",
" positions = [\n",
" [a/2-r/2, a/2, a/2],\n",
" [a/2+r/2, a/2, a/2],\n",
" ]\n",
" \n",
" if magnetism == 'FM':\n",
" if m == 0:\n",
" continue\n",
" magmoms = [m, m]\n",
" elif magnetism == 'AFM':\n",
" if m == 0:\n",
" continue\n",
" magmoms = [m, -m]\n",
" elif magnetism == 'NM':\n",
" magmoms = [0, 0]\n",
" \n",
" traj_fpath = out_dir / \"traj.extxyz\"\n",
"\n",
" if traj_fpath.exists():\n",
" traj = read(traj_fpath, index=\":\")\n",
" skip = len(traj)\n",
" atoms = traj[-1]\n",
" else:\n",
" # Create the unit cell with two atoms\n",
" atoms = Atoms(\n",
" da, \n",
" positions=positions,\n",
" magmoms=magmoms,\n",
" cell=[a, a+0.001, a+0.002], \n",
" pbc=True\n",
" )\n",
" \n",
" print(atoms)\n",
" \n",
" restart_fpath = out_dir / 'restart.gpw'\n",
"\n",
" calc = GPAW(\n",
" mode=PW(1000),\n",
" xc='PBE',\n",
" spinpol=True,\n",
" # basis='dzp'\n",
" basis='szp(dzp)',\n",
" # h=0.25,\n",
" # nbands=0 if element.is_noble_gas else '110%',\n",
" hund=False,\n",
" mixer=MixerDif(0.01, 1, 1) if element.is_transition_metal else MixerDif(0.25, 3, 10),\n",
" eigensolver='cg', #'rmm-diis', #Davidson(3), # This solver can parallelize over bands Davidson(3), #\n",
" occupations=FermiDirac(0.0, fixmagmom=False), # if not element.is_metal else FermiDirac(0.2, fixmagmom=False),\n",
" # eigensolver=LCAOETDM(),\n",
" # # searchdir_algo={'name': 'l-bfgs-p', 'memory': 10}),\n",
" # occupations={'name': 'fixed-uniform'},\n",
" # mixer={'backend': 'no-mixing'},\n",
" # nbands='nao',\n",
" symmetry={'point_group': False},\n",
" txt=out_dir / 'out.txt',\n",
" convergence={\n",
" 'eigenstates': 1e-5,\n",
" 'density': 5e-3,\n",
" 'energy': 5e-4,\n",
" # 'bands': 4\n",
" },\n",
" # {'energy': 0.0005, # eV / electron\n",
" # 'density': 1.0e-4, # electrons / electron\n",
" # 'eigenstates': 4.0e-8, # eV^2 / electron\n",
" # 'bands': 'occupied'}\n",
" )\n",
" # calc.attach(calc.write, 10, restart_fpath, mode='all')\n",
"\n",
" atoms.calc = calc\n",
" \n",
" # cdft = CDFT(calc=calc, atoms=atoms, spinspin_regions= \n",
" # atoms.calc = cdft\n",
"\n",
" for i, r in enumerate(tqdm(np.flip(rs))):\n",
"\n",
" if i < skip:\n",
" continue\n",
"\n",
" positions = [\n",
" [a/2-r/2, a/2, a/2],\n",
" [a/2+r/2, a/2, a/2],\n",
" ]\n",
" \n",
" # if i > 0: \n",
" # magmoms = atoms.get_magnetic_moments()\n",
" # m = min(abs(magmoms[0])*1.2, m)\n",
" # magmoms = magmoms*m/np.abs(magmoms)\n",
" \n",
" atoms.set_initial_magnetic_moments(magmoms)\n",
" \n",
" atoms.set_positions(positions)\n",
"\n",
" e[i] = atoms.get_potential_energy()\n",
" \n",
" atoms.calc.results.update({\n",
" \"forces\": atoms.get_forces()\n",
" })\n",
"\n",
" write(traj_fpath, atoms, append=\"a\")\n",
" except Exception as e:\n",
" print(e)\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "a0ac2c09-370b-4fdd-bf74-ea5c4ade0215",
"metadata": {},
"outputs": [],
"source": [
"\n",
"\n",
"df = pd.DataFrame(columns=['name', 'method', 'R', 'E', 'F', 'S^2'])\n",
"\n",
"\n",
"\n",
"for symbol in tqdm(chemical_symbols):\n",
" \n",
" for magnetism in ['AFM', 'FM', 'NM']:\n",
" \n",
" da = symbol + symbol\n",
"\n",
" # out_dir = Path(da)\n",
" out_dir = Path(str(da + f\"_{magnetism}\"))\n",
"\n",
" traj_fpath = out_dir / \"traj.extxyz\"\n",
"\n",
" if traj_fpath.exists():\n",
" traj = read(traj_fpath, index=\":\")\n",
" else:\n",
" continue\n",
"\n",
" Rs, Es, Fs, S2s = [], [], [], []\n",
" for atoms in traj:\n",
"\n",
" vec = atoms.positions[1] - atoms.positions[0]\n",
" r = np.linalg.norm(vec)\n",
" e = atoms.get_potential_energy()\n",
" # f = np.inner(vec/r, atoms.get_forces()[1])\n",
" # s2 = np.mean(np.power(atoms.get_magnetic_moments(), 2))\n",
"\n",
" Rs.append(r)\n",
" Es.append(e)\n",
" # Fs.append(f)\n",
" # S2s.append(s2)\n",
"\n",
" data = {\n",
" 'name': da,\n",
" 'method': f'GGA-PBE (GPAW): {magnetism}',\n",
" 'R': Rs,\n",
" 'E': Es,\n",
" 'F': Fs,\n",
" 'S^2': S2s\n",
" }\n",
"\n",
" df = pd.concat([df, pd.DataFrame([data])], ignore_index=True)\n",
"\n",
"json_fpath = 'homonuclear-diatomics.json'\n",
"\n",
"df.to_json(json_fpath, orient='records') "
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "5d4a7312-a619-411f-9c6f-36c40cd47a34",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "mlip-arena",
"language": "python",
"name": "mlip-arena"
},
"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.11.8"
},
"widgets": {
"application/vnd.jupyter.widget-state+json": {
"state": {},
"version_major": 2,
"version_minor": 0
}
}
},
"nbformat": 4,
"nbformat_minor": 5
}
|