-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathexisting_CSD_data.py
More file actions
56 lines (53 loc) · 2.3 KB
/
Copy pathexisting_CSD_data.py
File metadata and controls
56 lines (53 loc) · 2.3 KB
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
import ccdc
import sys
import os
import numpy as np
entries = ccdc.io.EntryReader('CSD')
family = sys.argv[1]
common_name = sys.argv[2]
Polymorphs = []
volumes_by_polymorph = {}
temperature_by_polymorph = {}
Refcode_by_polymorph = {}
dois_by_polymorph = {}
for i in range(9):
if i == 0:
num = ""
else:
num = "%02i" % i
full_name = f"{family}{num}"
print(full_name)
try:
entry = entries.entry(full_name)
except Exception as e:
print(f"Could not retrieve crystal for {full_name}: {e}")
break
polymorph = entry.polymorph if entry.polymorph else "Unknown"
volume = entry.crystal.cell_volume
if volume is not None:
if polymorph not in volumes_by_polymorph:
volumes_by_polymorph[polymorph] = []
volumes_by_polymorph[polymorph].append(volume)
temperature = entry.temperature if entry.temperature else "Unknown"
if temperature is not None:
if polymorph not in temperature_by_polymorph:
temperature_by_polymorph[polymorph] = []
temperature_by_polymorph[polymorph].append(temperature)
refcode = entry.identifier
if polymorph not in Refcode_by_polymorph:
Refcode_by_polymorph[polymorph] = []
Refcode_by_polymorph[polymorph].append(refcode)
doi = entry.publication.doi if entry.publication and entry.publication.doi else "Unknown"
if polymorph not in dois_by_polymorph:
dois_by_polymorph[polymorph] = []
dois_by_polymorph[polymorph].append(doi)
if os.path.exists(common_name):
print(f"folder {common_name} exists.")
else:
print(f"making folder {common_name}")
os.mkdir(common_name)
for polymorph, volumes in volumes_by_polymorph.items():
output_file = open(os.path.join(common_name, f"{polymorph}_volume.csv"), 'w')
output_file.write("%s\n" % (Refcode_by_polymorph[polymorph][0])) # should be best R factor refcode rather than first really
output_file.write("Identifier, Property , Value (Angstrom^3), Std, N, Name, Reference , Comment\n")
output_file.write(f"1, Unit Cell Volume @ {temperature_by_polymorph[polymorph][0]}, {np.mean(volumes):.2f}, {np.std(volumes):.2f}, {len(volumes)}, ,{dois_by_polymorph[polymorph][0]}, generated by automatic script; add Name and double check temperature etc.\n")