Skip to content

Commit a83fd79

Browse files
committed
add partial constriants #191
1 parent 41e610c commit a83fd79

File tree

5 files changed

+93
-15
lines changed

5 files changed

+93
-15
lines changed

doc/Usage.rst

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,61 @@ This would create a crystal structure with 3D structure with space group 225, 12
4242
4343
would create a random BaTiO3 crystal.
4444

45+
Sometimes, it is also convenient to generate the random crystal with partial information
46+
47+
.. code-block:: Python
48+
49+
my_crystal.from_random(3, 99, ['Ba','Ti','O'], [1,1,3])
50+
my_crystal
51+
------Random Crystal------
52+
Composition: Ba1 Ti1 O3
53+
Dimension: 3
54+
Group: P4mm (99)
55+
Volume factor: 1.0
56+
tetragonal lattice: 5.1029 5.1029 4.3018 90.0000 90.0000 90.0000
57+
Wyckoff sites:
58+
Ba @ [0.5000 0.5000 0.3612], Wyckoff letter: 1b, Site symmetry: 4 m m
59+
Ti @ [0.5000 0.5000 0.8701], Wyckoff letter: 1b, Site symmetry: 4 m m
60+
O @ [0.5000 0.0000 0.0823], Wyckoff letter: 2c, Site symmetry: 2 mm .
61+
O @ [0.5000 0.5000 0.8177], Wyckoff letter: 1b, Site symmetry: 4 m m
62+
63+
from pyxtal.lattice import Lattice
64+
cell = Lattice.from_para(7.8758, 7.9794, 5.6139, 90, 90, 90, ltype='orthorhombic')
65+
spg = 58
66+
elements = ['Al', 'Si', 'O']
67+
composition = [8, 4, 20]
68+
69+
sites = [{"4e": [0.0000, 0.0000, 0.2418],
70+
"4g": [0.1294, 0.6392, 0.0000],
71+
},
72+
{"4g": [0.2458, 0.2522, 0.0000]},
73+
{"4g": [0.4241, 0.3636, 0.0000]}, #partial information on oxygen sites
74+
]
75+
76+
s = pyxtal()
77+
s.from_random(3, spg, elements, composition, lattice=cell, sites=sites)
78+
print(s)
79+
80+
------Crystal from random------
81+
Dimension: 3
82+
Composition: O20Si4Al8
83+
Group: Pnnm (58)
84+
7.8758, 7.9794, 5.6139, 90.0000, 90.0000, 90.0000, orthorhombic
85+
Wyckoff sites:
86+
Al @ [ 0.0000 0.0000 0.2418], WP [4e] Site [..2]
87+
Al @ [ 0.1294 0.6392 0.0000], WP [4g] Site [..m]
88+
Si @ [ 0.2458 0.2522 0.0000], WP [4g] Site [..m]
89+
O @ [ 0.4241 0.3636 0.0000], WP [4g] Site [..m]
90+
O @ [ 0.5538 0.2648 0.0000], WP [4g] Site [..m]
91+
O @ [ 0.0000 0.5000 0.6057], WP [4f] Site [..2]
92+
O @ [ 0.8809 0.5970 0.0786], WP [8h] Site [1]
93+
94+
95+
The above script will create a crystal with constrained unit cell and sites on Si/Al, but random sites on O sites.
96+
97+
98+
99+
45100
If the generation is successful, the value ``my_crystal.valid`` will be set to ``True``; otherwise, it will be ``False``.
46101

47102
2D Crystals

doc/conf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@
2424
author = "Qiang Zhu, Scott Fredericks, Kevin Parrish"
2525

2626
# The short X.Y version
27-
version = "0.4.4"
27+
version = "0.4.5"
2828
# The full version, including alpha/beta/rc tags
29-
release = "0.4.4"
29+
release = "0.4.5"
3030

3131

3232
# -- General configuration ---------------------------------------------------

doc/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ PyXtal (pronounced ``pie-crystal``) is an open source Python library for the ab-
2323
- Structural manipulation via symmetry relation (both subgroup and supergroup)
2424
- Geometry optimization from built-in and external optimization methods
2525

26-
The current version is ``0.4.4`` at `GitHub <https://github.com/qzhu2017/PyXtal>`_. It is available for use under the MIT license. Expect updates upon request by `Qiang Zhu\'s group <http://www.physics.unlv.edu/~qzhu/index.html>`_ at University of Nevada Las Vegas.
26+
The current version is ``0.4.5`` at `GitHub <https://github.com/qzhu2017/PyXtal>`_. It is available for use under the MIT license. Expect updates upon request by `Qiang Zhu\'s group <http://www.physics.unlv.edu/~qzhu/index.html>`_ at University of Nevada Las Vegas.
2727

2828
PyXtal is an open source project. You are welcome to contribute it directly via the `GitHub platform <https://github.com/qzhu2017/PyXtal>`_ or send your comments and suggestions to the `developer <http://www.physics.unlv.edu/~qzhu/>`_.
2929

pyxtal/crystal.py

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,9 @@ def set_sites(self, sites):
141141
for i, specie in enumerate(self.species):
142142
if sites is not None and sites[i] is not None and len(sites[i])>0:
143143
self._check_consistency(sites[i], self.numIons[i])
144-
if type(sites[i][0]) is dict:
144+
if type(sites[i]) is dict:
145145
self.sites[specie] = []
146-
for item in sites[i][0].items():
146+
for item in sites[i].items():
147147
self.sites[specie].append({item[0]: item[1]})
148148
else:
149149
self.sites[specie] = sites[i]
@@ -311,7 +311,7 @@ def _set_ion_wyckoffs(self, numIon, specie, cell, wyks):
311311
cycle = 0
312312
while cycle < wyckoff_attempts:
313313
# Choose a random WP for given multiplicity: 2a, 2b
314-
if sites_list is not None:
314+
if sites_list is not None and len(sites_list)>0:
315315
site = sites_list[0]
316316
else: # Selecting the merging
317317
site = None
@@ -343,7 +343,7 @@ def _set_ion_wyckoffs(self, numIon, specie, cell, wyks):
343343

344344
# Check current WP against existing WP's
345345
if self.check_wp(wyckoff_sites_tmp, wyks, cell, new_site):
346-
if sites_list is not None:
346+
if sites_list is not None and len(sites_list)>0:
347347
sites_list.pop(0)
348348
wyckoff_sites_tmp.append(new_site)
349349
numIon_added += new_site.multiplicity
@@ -379,8 +379,20 @@ def _check_consistency(self, site, numIon):
379379
if numIon == num:
380380
return True
381381
else:
382-
msg = "\nThe requested number of atoms is inconsistent: " + str(site)
383-
msg += "\nfrom numIons: {:d}".format(numIon)
384-
msg += "\nfrom Wyckoff list: {:d}".format(num)
385-
raise ValueError(msg)
382+
diff = numIon - num
383+
if diff > 0:
384+
#check if compatible
385+
compat, self.degrees = self.group.check_compatible([diff])
386+
if compat:
387+
return True
388+
else:
389+
msg += "\nfrom numIons: {:d}".format(numIon)
390+
msg += "\nfrom Wyckoff list: {:d}".format(num)
391+
msg = "\nThe number of atoms is incompatible with composition: " + str(site)
392+
raise ValueError(msg)
393+
else:
394+
msg += "\nfrom numIons: {:d}".format(numIon)
395+
msg += "\nfrom Wyckoff list: {:d}".format(num)
396+
msg = "\nThe requested number of atoms is greater than composition: " + str(site)
397+
raise ValueError(msg)
386398

pyxtal/test_all.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -933,17 +933,28 @@ def test_Al2SiO5(self):
933933
spg = 58
934934
elements = ['Al', 'Si', 'O']
935935
composition = [8, 4, 20]
936-
sites = [[{"4e": [0.0000, 0.0000, 0.2418],
937-
"4g": [0.1294, 0.6392, 0.0000],
938-
}],
939-
[{"4g": [0.2458, 0.2522, 0.0000]}],
936+
sites = [{"4e": [0.0000, 0.0000, 0.2418],
937+
"4g": [0.1294, 0.6392, 0.0000],
938+
},
939+
{"4g": [0.2458, 0.2522, 0.0000]},
940940
[], #empty for oxygen
941941
]
942942

943943
s = pyxtal()
944944
s.from_random(3, spg, elements, composition, lattice=cell, sites=sites)
945945
self.assertTrue(s.valid)
946946

947+
sites2 = [{"4e": [0.0000, 0.0000, 0.2418],
948+
"4g": [0.1294, 0.6392, 0.0000],
949+
},
950+
{"4g": [0.2458, 0.2522, 0.0000]},
951+
{"4g": [0.4241, 0.3636, 0.0000]}, #partial info on O
952+
]
953+
954+
s = pyxtal()
955+
s.from_random(3, spg, elements, composition, lattice=cell, sites=sites2)
956+
self.assertTrue(s.valid)
957+
947958
class Test_operations(unittest.TestCase):
948959
def test_inverse(self):
949960
coord0 = [0.35, 0.1, 0.4]

0 commit comments

Comments
 (0)