Commit
·
fca6a37
1
Parent(s):
b6177a3
add first version
Browse files- .gitattributes +2 -0
- .gitignore +4 -0
- dump.py +202 -0
- oqmd.tar.gz +3 -0
.gitattributes
CHANGED
|
@@ -53,3 +53,5 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 53 |
*.jpg filter=lfs diff=lfs merge=lfs -text
|
| 54 |
*.jpeg filter=lfs diff=lfs merge=lfs -text
|
| 55 |
*.webp filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
| 53 |
*.jpg filter=lfs diff=lfs merge=lfs -text
|
| 54 |
*.jpeg filter=lfs diff=lfs merge=lfs -text
|
| 55 |
*.webp filter=lfs diff=lfs merge=lfs -text
|
| 56 |
+
materials-project.tar.gz filter=lfs diff=lfs merge=lfs -text
|
| 57 |
+
*.tar.gz filter=lfs diff=lfs merge=lfs -text
|
.gitignore
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
unzipped
|
| 2 |
+
*.hdf5
|
| 3 |
+
*.json
|
| 4 |
+
*.zip
|
dump.py
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
import mysql.connector
|
| 3 |
+
import numpy as np
|
| 4 |
+
import tqdm
|
| 5 |
+
from tqdm.contrib.concurrent import process_map
|
| 6 |
+
from ase.data import atomic_numbers
|
| 7 |
+
|
| 8 |
+
from materials_toolkit.data import HDF5Dataset, StructureData, batching, Batching
|
| 9 |
+
|
| 10 |
+
import os
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
@batching(
|
| 14 |
+
entry_id=Batching(dtype=torch.long),
|
| 15 |
+
structure_id=Batching(dtype=torch.long),
|
| 16 |
+
calculation_id=Batching(dtype=torch.long),
|
| 17 |
+
spacegroup=Batching(dtype=torch.long),
|
| 18 |
+
)
|
| 19 |
+
class OQMDData(StructureData):
|
| 20 |
+
pass
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
class OQMD(HDF5Dataset):
|
| 24 |
+
data_class = OQMDData
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
def get_all_structures(host, user, password, database="qmdb"):
|
| 28 |
+
|
| 29 |
+
with mysql.connector.connect(
|
| 30 |
+
host=host, user=user, password=password, database=database
|
| 31 |
+
) as db:
|
| 32 |
+
structures = []
|
| 33 |
+
with db.cursor() as c:
|
| 34 |
+
# calculate atoms count for all structures
|
| 35 |
+
c.execute(
|
| 36 |
+
'select TABLE_NAME from information_schema.tables where table_name="structures_natoms";'
|
| 37 |
+
)
|
| 38 |
+
if len(c.fetchall()) == 0:
|
| 39 |
+
c.execute(
|
| 40 |
+
"create table structures_natoms select structure_id,count(*) as natoms from atoms group by structure_id;"
|
| 41 |
+
)
|
| 42 |
+
|
| 43 |
+
# filter valid structures (natoms match between structures table and structures_natoms)
|
| 44 |
+
c.execute(
|
| 45 |
+
'select TABLE_NAME from information_schema.tables where table_name="valid_structure";'
|
| 46 |
+
)
|
| 47 |
+
if len(c.fetchall()) == 0:
|
| 48 |
+
c.execute(
|
| 49 |
+
"""
|
| 50 |
+
create table valid_structure
|
| 51 |
+
select structures.id as structure_id,structures.natoms as natoms from structures
|
| 52 |
+
inner join structures_natoms
|
| 53 |
+
on
|
| 54 |
+
structures.id=structures_natoms.structure_id
|
| 55 |
+
and structures.natoms=structures_natoms.natoms;
|
| 56 |
+
"""
|
| 57 |
+
)
|
| 58 |
+
|
| 59 |
+
# get minimal energy of an entry, select lower energy from converged calculations and reject lda setup
|
| 60 |
+
c.execute(
|
| 61 |
+
'select TABLE_NAME from information_schema.tables where table_name="entries_minimal_energy";'
|
| 62 |
+
)
|
| 63 |
+
if len(c.fetchall()) == 0: # TODO filtrer standard et static
|
| 64 |
+
c.execute(
|
| 65 |
+
f"""
|
| 66 |
+
create table entries_minimal_energy
|
| 67 |
+
select calculations.entry_id as entry_id, min(calculations.energy_pa) as energy_pa
|
| 68 |
+
from calculations
|
| 69 |
+
inner join valid_structure
|
| 70 |
+
on
|
| 71 |
+
calculations.converged is not null
|
| 72 |
+
and calculations.converged=true
|
| 73 |
+
and calculations.label NOT LIKE '%lda'
|
| 74 |
+
and (calculations.label LIKE 'static%'
|
| 75 |
+
or calculations.label LIKE 'standard%')
|
| 76 |
+
and valid_structure.structure_id=calculations.output_id
|
| 77 |
+
group by calculations.entry_id;
|
| 78 |
+
"""
|
| 79 |
+
)
|
| 80 |
+
|
| 81 |
+
c.execute(
|
| 82 |
+
'select TABLE_NAME from information_schema.tables where table_name="entries_with_structure";'
|
| 83 |
+
)
|
| 84 |
+
if len(c.fetchall()) == 0:
|
| 85 |
+
c.execute(
|
| 86 |
+
"""
|
| 87 |
+
create table entries_with_structure
|
| 88 |
+
select calculations.entry_id as entry_id, calculations.output_id as structure_id, calculations.id as calculation_id, calculations.label as calculation_label, calculations.energy_pa as energy_pa
|
| 89 |
+
from entries_minimal_energy
|
| 90 |
+
left join calculations
|
| 91 |
+
on
|
| 92 |
+
calculations.entry_id=entries_minimal_energy.entry_id
|
| 93 |
+
and calculations.energy_pa=entries_minimal_energy.energy_pa
|
| 94 |
+
inner join valid_structure
|
| 95 |
+
on
|
| 96 |
+
valid_structure.structure_id=calculations.output_id
|
| 97 |
+
group by calculations.entry_id;
|
| 98 |
+
"""
|
| 99 |
+
)
|
| 100 |
+
|
| 101 |
+
c.execute("select * from entries_with_structure;")
|
| 102 |
+
entries_calc = c.fetchall()
|
| 103 |
+
|
| 104 |
+
for entry_id, struct_id, calc_id, calc_label, energy_pa in tqdm.tqdm(
|
| 105 |
+
entries_calc
|
| 106 |
+
):
|
| 107 |
+
c.execute(
|
| 108 |
+
f"""
|
| 109 |
+
select struct.natoms, spacegroups.hm, struct.x1, struct.x2, struct.x3, struct.y1, struct.y2, struct.y3, struct.z1, struct.z2, struct.z3, struct.volume
|
| 110 |
+
from (
|
| 111 |
+
select natoms, x1, x2, x3, y1, y2, y3, z1, z2, z3, volume, coalesce(spacegroup_id, 1) as spacegroup_id
|
| 112 |
+
from structures
|
| 113 |
+
where structures.id={struct_id}
|
| 114 |
+
) as struct
|
| 115 |
+
inner join spacegroups on
|
| 116 |
+
struct.spacegroup_id=spacegroups.number;
|
| 117 |
+
"""
|
| 118 |
+
)
|
| 119 |
+
results = c.fetchall()
|
| 120 |
+
assert len(results) == 1, f"error structure {struct_id}"
|
| 121 |
+
(
|
| 122 |
+
natoms,
|
| 123 |
+
space_group,
|
| 124 |
+
x1,
|
| 125 |
+
x2,
|
| 126 |
+
x3,
|
| 127 |
+
y1,
|
| 128 |
+
y2,
|
| 129 |
+
y3,
|
| 130 |
+
z1,
|
| 131 |
+
z2,
|
| 132 |
+
z3,
|
| 133 |
+
volume,
|
| 134 |
+
) = results[0]
|
| 135 |
+
|
| 136 |
+
c.execute(
|
| 137 |
+
f"""
|
| 138 |
+
select element_id,x,y,z
|
| 139 |
+
from atoms
|
| 140 |
+
where structure_id={struct_id}
|
| 141 |
+
"""
|
| 142 |
+
)
|
| 143 |
+
atoms = c.fetchall()
|
| 144 |
+
|
| 145 |
+
if len(atoms) != natoms:
|
| 146 |
+
print(entry_id, struct_id, calc_label, energy_pa)
|
| 147 |
+
for element_id, x, y, z in atoms:
|
| 148 |
+
print(f"{element_id:>4s} {x:>.3f} {y:>.3f} {z:>.3f}")
|
| 149 |
+
|
| 150 |
+
assert len(atoms) == natoms, f"error {len(atoms)} {natoms}"
|
| 151 |
+
|
| 152 |
+
z_lst = []
|
| 153 |
+
coords = []
|
| 154 |
+
for e_id, x, y, z in atoms:
|
| 155 |
+
z_lst.append(atomic_numbers[e_id])
|
| 156 |
+
coords.append([x, y, z])
|
| 157 |
+
coords = np.array(coords)
|
| 158 |
+
cell = np.array([[x1, x2, x3], [y1, y2, y3], [z1, z2, z3]])
|
| 159 |
+
|
| 160 |
+
structures.append(
|
| 161 |
+
OQMDData(
|
| 162 |
+
z=torch.tensor(z_lst, dtype=torch.long).view(-1),
|
| 163 |
+
pos=torch.from_numpy(coords).float().view(-1, 3),
|
| 164 |
+
cell=torch.from_numpy(cell).float().view(1, 3, 3),
|
| 165 |
+
entry_id=torch.tensor([entry_id]).long().view(1),
|
| 166 |
+
structure_id=torch.tensor([struct_id]).long().view(1),
|
| 167 |
+
calculation_id=torch.tensor([calc_id]).long().view(1),
|
| 168 |
+
spacegroup=torch.tensor([space_group]).long().view(1),
|
| 169 |
+
energy_pa=torch.tensor([energy_pa]).float().view(1),
|
| 170 |
+
)
|
| 171 |
+
)
|
| 172 |
+
|
| 173 |
+
return structures
|
| 174 |
+
|
| 175 |
+
|
| 176 |
+
def main():
|
| 177 |
+
import argparse
|
| 178 |
+
|
| 179 |
+
parser = argparse.ArgumentParser()
|
| 180 |
+
|
| 181 |
+
parser.add_argument("--host", default="localhost", help="mysql host serveur")
|
| 182 |
+
parser.add_argument("--database", default="qmdb", help="name of the database")
|
| 183 |
+
parser.add_argument("--user", help="user of the mysql server")
|
| 184 |
+
parser.add_argument("--password", help="password of the user")
|
| 185 |
+
|
| 186 |
+
args = parser.parse_args()
|
| 187 |
+
|
| 188 |
+
structures = get_all_structures(
|
| 189 |
+
host=args.host, user=args.user, password=args.password, database="qmdb"
|
| 190 |
+
)
|
| 191 |
+
|
| 192 |
+
oqmd_dir = os.path.join(".", "open-quantum-materials-database")
|
| 193 |
+
processed_dir = os.path.join(oqmd_dir, "processed")
|
| 194 |
+
|
| 195 |
+
HDF5Dataset.create_dataset(processed_dir, structures)
|
| 196 |
+
|
| 197 |
+
dataset = OQMD(oqmd_dir)
|
| 198 |
+
dataset.compute_convex_hulls()
|
| 199 |
+
|
| 200 |
+
|
| 201 |
+
if __name__ == "__main__":
|
| 202 |
+
main() # check entry 351317
|
oqmd.tar.gz
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:bafcfd85373fd0c9b6ff297a87a165cb781e4b748c01a547c60bf6747dcb9b2a
|
| 3 |
+
size 65561783
|