Skip to content

Commit 1603bc7

Browse files
committed
Usage example in README
1 parent e001078 commit 1603bc7

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,37 @@ Contents
5656
* **jscragg_2011.csv** Data file containing kinetic model stability boundary
5757
data from [Scragg et al. (2011)](http://dx.doi.org/10.1021/cm202379s). This
5858
data is used in **plots/DG_CZTS_SnS_Scragg.py** to reproduce Fig. 7 of [Jackson and Walsh (2014)](http://dx.doi.org/10.1039/c4ta00892h).
59+
60+
Example
61+
-------
62+
63+
Each material is made available as an object in the module namespace,
64+
and has methods which retrieve various properties. For example, to
65+
generate a CSV file containing the chemical potentials of a selection of phases:
66+
67+
``` python
68+
import csv
69+
import numpy as np
70+
from materials import CZTS_kesterite, Cu, beta_Sn, alpha_Sn
71+
from materials import Cu2S, SnS2, SnS, Sn2S3, ZnS, S2, S8
72+
73+
T = np.arange(400, 1200, 50)
74+
75+
titles = []
76+
data = []
77+
for material in (CZTS_kesterite, Cu, beta_Sn,
78+
alpha_Sn, Cu2S, SnS2,
79+
SnS, Sn2S3, ZnS, S2, S8):
80+
81+
titles.append(material.name)
82+
data.append(list(material.mu_kJ(T, 1E5)))
83+
84+
# Zip and list unpacking can be used together to transpose
85+
# a matrix expressed as a list of lists
86+
data = zip(*data)
87+
88+
with open('mu_data_Jmol.csv', 'wb') as f:
89+
writer = csv.writer(f)
90+
writer.writerow(titles)
91+
writer.writerows(data)
92+
```

0 commit comments

Comments
 (0)