Skip to content

Commit 9248a45

Browse files
committed
complete Alex-AMC edits and suggestions
1 parent 3dbc9dc commit 9248a45

File tree

2 files changed

+42
-31
lines changed

2 files changed

+42
-31
lines changed

scripts/particle_rugosity/ReadMe.md

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Using a protocol similar to that reported by [Cruz-Cabeza and colleagues](https:
1515
takes a crystal structure or refcode as an argument and will use the CCDC BFDH
1616
morphology module to simulate the predicted particle shape. The facet hkl planes are
1717
then obtained and the rugosity of these planes is calculated using the [CCDC rugosity function](https://downloads.ccdc.cam.ac.uk/documentation/API/descriptive_docs/particle.html) (including a scan of
18-
different off-sets from the origin to identify the minimum rugosity of that crystal
18+
different offsets from the origin to identify the minimum rugosity of that crystal
1919
plane). Finally, the total particle rugosity is calculated by weighted average
2020
according to the facet surface areas.
2121

@@ -27,7 +27,7 @@ according to the facet surface areas.
2727

2828
## Licensing Requirements
2929

30-
- CSD-Core
30+
- CSD-Core, CSD-Particle
3131

3232
## Instructions on Running
3333
### Linux command line
@@ -37,7 +37,7 @@ according to the facet surface areas.
3737
$ python particle_rugosity.py AABHTZ
3838
The crystal structure AABHTZ has been loaded
3939
Calculating particle rugosity ...
40-
AABHTZ particle rugosity: 1.5073781143188552
40+
AABHTZ particle rugosity: 1.507
4141
~~~
4242
OR
4343
~~~
@@ -60,22 +60,21 @@ C:\Program Files\CCDC\Python_API_2022\
6060
the last line is the folder location where you need to move the particle\_rugostiy.py file
6161
- now the script can be run in the CSD Python API to calculate the rugosity of any CSD entry using:
6262
~~~
63-
>>> import sys
64-
>>> import subprocess
65-
>>> subprocess.call([sys.executable, 'particle_rugosity.py', 'AABHTZ'])
63+
>>> from particle_rugosity import particle_rugosity
64+
>>> particle_rugosity('AABHTZ')
6665
The crystal structure AABHTZ has been loaded
6766
Calculating particle rugosity ...
68-
AABHTZ particle rugosity: 1.5073781143188552
67+
AABHTZ particle rugosity: 1.507
6968
~~~
7069
OR
7170
- if you want to run your own crystal structures, make a folder (eg. rugosity_calc) in Python_API_(year), and add your
7271
crystal structure file to that folder
7372
- modify the argument to include the file path
7473
~~~
75-
>>> subprocess.call([sys.executable, 'particle_rugosity.py', 'rugosity_calc/AABHTZ.cif'])
74+
>>> particle_rugosity('rugosity_calc/AABHTZ.cif')
7675
The crystal structure rugosity_calc/AABHTZ.cif has been loaded
7776
Calculating particle rugosity ...
78-
AABHTZ particle rugosity: 1.5073781143188552
77+
rugosity_calc/AABHTZ.cif particle rugosity: 1.507
7978
~~~
8079

8180
## Author

scripts/particle_rugosity/particle_rugosity.py

Lines changed: 34 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,38 @@
22
# requires a CCDC license, and loading of the CSD-python miniconda environment if run from Linux command line
33

44
# import ccdc modules
5+
import os as opsys
6+
import argparse
57
from ccdc.io import CrystalReader
68
from ccdc.particle import Surface
79
from ccdc.morphology import BFDHMorphology
810

9-
def particle_rugosity(crystal):
11+
def particle_rugosity(xname):
12+
# xname is a string, either refcode (eg: 'AABHTZ') or filename (eg: 'AABHTZ.cif')
1013
# load structure, either (1) crystal structure file in working directory, or
1114
# (2) CSD refcode
12-
head, sep, tail = crystal.partition('.')
13-
if sep == '.':
14-
# agrument is crystal structure file
15-
xname = crystal
16-
xtal1 = CrystalReader(xname)
17-
xtal = xtal1[0]
18-
xtal1.close
15+
if opsys.path.isfile(xname):
16+
try:
17+
# agrument is crystal structure file
18+
xtal1 = CrystalReader(xname)
19+
xtal = xtal1[0]
20+
xtal1.close
21+
except:
22+
print("Error in reading crystal structure input.\nPlease enter a CSD refcode or provide the path to your crystal structure file")
23+
input('Press ENTER to exit')
24+
quit()
1925
else:
20-
# agrument is a CSD refcode
21-
xname = crystal
22-
xtal = CrystalReader('CSD').crystal(xname)
23-
24-
print(f"The crystal structure {crystal} has been loaded")
26+
try:
27+
# agrument is a CSD refcode
28+
xtal = CrystalReader('CSD').crystal(xname)
29+
except:
30+
print("Error in reading crystal structure input.\nPlease enter a CSD refcode or provide the path to your crystal structure file")
31+
input('Press ENTER to exit')
32+
quit()
33+
34+
print(f"The crystal structure {xname} has been loaded")
2535
print("Calculating particle rugosity ...")
36+
2637
# run BFDH morphology to determine predicted particle surface area = hkl planes, and d-spacing of the planes
2738
morphology = BFDHMorphology(xtal)
2839
facets = morphology.facets
@@ -32,11 +43,13 @@ def particle_rugosity(crystal):
3243
facets_relA = [morphology.relative_area(mi) for mi in all_mi]
3344
all_d_hkl = [f.miller_indices.d_spacing for f in facets]
3445
num_face = len(all_d_hkl)
46+
3547
# generate surfaces and record rugosity, weigh by particle surface area
3648
w_part_rug = []
3749
for i in range(num_face):
3850
hkl = all_hkl[i]
3951
rug_list = []
52+
4053
# check rugosity of crystal plane at 0, 0.25, 0.5, and 0.75 offset from origin
4154
for split in range(1,5):
4255
os = all_d_hkl[i] / split
@@ -50,16 +63,15 @@ def particle_rugosity(crystal):
5063

5164
# sum weighted rugosity values and print total particle rugosity
5265
tot_rug = sum(w_part_rug)
53-
print(f'{crystal} particle rugosity: ',tot_rug)
66+
print(f'{xname} particle rugosity: ',round(tot_rug, 3))
5467

5568
# ================================
56-
# argument parser
57-
import argparse
58-
parser = argparse.ArgumentParser()
59-
parser.add_argument("input_x")
60-
args = parser.parse_args()
61-
crystal = args.input_x
69+
if __name__=='__main__':
70+
parser = argparse.ArgumentParser()
71+
parser.add_argument("input_x")
72+
args = parser.parse_args()
73+
crystal = args.input_x
6274

63-
# run code
64-
particle_rugosity(crystal)
75+
# run code
76+
particle_rugosity(crystal)
6577

0 commit comments

Comments
 (0)