FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Fixed broken parser. Added simple test to tests directory. · diffpy/diffpy.structure@50c1a7d · GitHub

Repository navigation

Commit 50c1a7d

Browse files
committed
Fixed broken parser. Added simple test to tests directory.
1 parent b4e7d05 commit 50c1a7d

5 files changed

Lines changed: 66 additions & 27 deletions

File tree

‎Structure/Parsers/P_bratoms.py‎

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ def toLines(self, stru):
164164
lines = []
165165

166166
# title
167-
titles = structure.title.split("\n")
167+
titles = stru.title.split("\n")
168168
for t in titles:
169169
lines.append("title = %s"%t)
170170

@@ -221,20 +221,3 @@ def getParser():
221221
return P_bratoms()
222222

223223
# End of file
224-
225-
if __name__ == "__main__":
226-
227-
files = ["GaAs.inp"]
228-
229-
ep = getParser()
230-
231-
for fn in files:
232-
infile = file(fn, 'r')
233-
fstr = infile.read()
234-
infile.close()
235-
lines = fstr.split("\n")
236-
structure = ep.parseLines(lines)
237-
lines = ep.toLines(structure)
238-
print "\n".join(lines)
239-
240-

‎Structure/expansion/makeCuboctahedron.py‎

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,15 @@ def makeCuboctahedron(S, dist):
1313
Arguments
1414
S -- A Structure instance
1515
dist -- Distance from center to nearest face
16+
axis -- Tuple defining the z-axis of the cuboctahedron (default
17+
(0,0,1)).
1618
1719
Returns a new structure instance
1820
"""
1921

2022
# Create a supercell large enough for the ellipsoid
2123
frac = S.lattice.fractional((dist, dist, dist))
22-
mno = map(ceil, 4*frac)
24+
mno = map(ceil, 2*frac)
2325
# Make the supercell
2426
from supercell import supercell
2527
newS = supercell(S, mno)
@@ -30,24 +32,19 @@ def makeCuboctahedron(S, dist):
3032

3133
# Make the cuboctahedron template
3234
from geometry.composites import cuboctahedron
33-
from geometry.operations import translate
35+
from geometry.operations import translate, rotate
3436
c0 = translate(cuboctahedron(dist), lat.cartesian(newS[ncenter].xyz))
3537

3638
# Cut out an octahedron
3739
from geometry import locate
38-
delList = []
3940

4041
N = len(newS)
4142
j = N
4243
for i in xrange(N):
43-
j -= 1
4444

45-
xyz = lat.cartesian(newS[j].xyz)
45+
xyz = lat.cartesian(newS[N-1-i].xyz)
4646
if locate(xyz, c0) == 1:
47-
delList.append(j)
48-
49-
for i in delList:
50-
newS.pop(i)
47+
newS.pop(N-1-i)
5148

5249
return newS
5350

‎tests/TestParsers.py‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,21 @@ def test_writeStr_cif(self):
416416
stru.read(datafile('CdSe_bulk.stru'), 'pdffit')
417417
s_s = stru.writeStr(self.format)
418418

419+
##############################################################################
420+
class TestP_bratoms(unittest.TestCase):
421+
"""test Parser for Bruce Ravel's atoms file format"""
422+
423+
def setUp(self):
424+
self.stru = Structure()
425+
self.format = "bratoms"
426+
self.places = 6
427+
428+
def test_writeStr_cif(self):
429+
"""check conversion to CIF string"""
430+
stru = self.stru
431+
stru.read(datafile('GaAs.inp'), 'bratoms')
432+
s_s = stru.writeStr(self.format)
433+
419434
# End of TestP_cif
420435

421436

‎tests/testdata/CdSe-wurtzite.stru‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
title Cell structure file of CdSe #186
2+
format pdffit
3+
scale 1.000000
4+
sharp 0.000000, 0.000000, 1.000000, 0.000000
5+
spcgr P63mc
6+
cell 4.300000, 4.300000, 7.010000, 90.000000, 90.000000, 120.000000
7+
dcell 0.000493, 0.000493, 0.001368, 0.000000, 0.000000, 0.000000
8+
ncell 1, 1, 1, 4
9+
atoms
10+
CD 0.33340001 0.66670001 0.00000000 1.0000
11+
0.00000000 0.00000000 0.00000000 0.0000
12+
0.01400000 0.01400000 0.01400000
13+
0.00011127 0.00011127 0.00019575
14+
0.00000000 0.00000000 0.00000000
15+
0.00000000 0.00000000 0.00000000
16+
CD 0.66659999 0.33329999 0.50000000 1.0000
17+
0.00000000 0.00000000 0.00000000 0.0000
18+
0.01400000 0.01400000 0.01400000
19+
0.00011127 0.00011127 0.00019575
20+
0.00000000 0.00000000 0.00000000
21+
0.00000000 0.00000000 0.00000000
22+
SE 0.33340001 0.66670001 0.37500000 1.0000
23+
0.00000000 0.00000000 0.00000000 0.0000
24+
0.01500000 0.01500000 0.01500000
25+
0.00022268 0.00022268 0.00071372
26+
0.00000000 0.00000000 0.00000000
27+
0.00000000 0.00000000 0.00000000
28+
SE 0.66659999 0.33329999 0.87500000 1.0000
29+
0.00000000 0.00000000 0.00000000 0.0000
30+
0.01500000 0.01500000 0.01500000
31+
0.00022268 0.00022268 0.00071372
32+
0.00000000 0.00000000 0.00000000
33+
0.00000000 0.00000000 0.00000000

‎tests/testdata/GaAs.inp‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
!This file is generated by atoms.py.
2+
title = GaAs
3+
a = 5.6537 b = 5.6537 c = 5.6537
4+
alpha = 90.000000 beta = 90.000000 gamma = 90.000000
5+
space = F-43m
6+
core = As
7+
edge = K
8+
atoms
9+
! x y z tag occ
10+
AS 0.250000 0.250000 0.250000 As 1.0000
11+
GA 0.000000 0.000000 0.000000 Ga 1.0000

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL