def prep_m(): try: d = pickle.load(open('elems.pkl', 'rb')) SpGrp.allelems = d[0] SpGrp.allhasI = d[1] except: ## ... parse and save to file ls = open('elems.dat').readlines() ls = filter(lambda l: l, map(lambda l: l.strip(), ls)) for sls in groupby(ls, 4): num, snum, inv, s, cnt = map(lambda s: int(s), sls[0].split()) mats = [Mat(0, 0, 0, 0, 0, 0, 0, 0, 0) for i in xrange(cnt)] ## create empty matrices vecs = [Vec(0, 0, 0) for i in xrange(cnt)] ## ..and empty vectors for i in xrange(1, 4): prts = map(lambda s: float(s), sls[i].split()) for j, els in enumerate(groupby( prts, 4)): ## group by (m11, m12, m13, v1) groups mats[j][i - 1] = els[:-1] ## set one row of matrix vecs[j][i - 1] = els[-1] ## set one coord of vec els = map(lambda e: SGElem(e[0], e[1]), zip(mats, vecs)) SpGrp.allelems[num - 1].append( els) ## SpGrp[ num ][ subnum ] = [ elem1, elem2, ... ] SpGrp.allhasI[num - 1].append(inv) f = open('elems.pkl', 'wb') pickle.dump((SpGrp.allelems, SpGrp.allhasI), f, -1) f.close()
def prep_m(): try: d = pickle.load( open( 'elems.pkl', 'rb' ) ) SpGrp.allelems = d[ 0 ] SpGrp.allhasI = d[ 1 ] except: ## ... parse and save to file ls = open( 'elems.dat' ).readlines() ls = filter( lambda l: l, map( lambda l: l.strip(), ls ) ) for sls in groupby( ls, 4 ): num, snum, inv, s, cnt = map( lambda s: int( s ), sls[ 0 ].split() ) mats = [ Mat( 0,0,0,0,0,0,0,0,0 ) for i in xrange( cnt ) ] ## create empty matrices vecs = [ Vec( 0,0,0 ) for i in xrange( cnt ) ] ## ..and empty vectors for i in xrange( 1, 4 ): prts = map( lambda s: float( s ), sls[ i ].split() ) for j, els in enumerate( groupby( prts, 4 ) ): ## group by (m11, m12, m13, v1) groups mats[ j ][ i-1 ] = els[ :-1 ] ## set one row of matrix vecs[ j ][ i-1 ] = els[ -1 ] ## set one coord of vec els = map( lambda e: SGElem( e[0], e[1] ), zip( mats, vecs ) ) SpGrp.allelems[ num-1 ].append( els ) ## SpGrp[ num ][ subnum ] = [ elem1, elem2, ... ] SpGrp.allhasI[ num-1 ].append( inv ) f = open( 'elems.pkl', 'wb' ) pickle.dump( ( SpGrp.allelems, SpGrp.allhasI ), f, -1 ) f.close()
yield res ls = open( 'spgrp.dat' ).readlines() ls = ls[ 235: ] ## drop conversion data exp = re.compile( r'^spgr\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(.*)$' ) data = [ [] for i in xrange( 230 ) ] for s in sg( ls ): res = exp.match( s[ 0 ] ) if res: num, snum, laue, inv, ngp, nsp, ngen = map( int, res.groups()[:-1] ) symb = res.groups()[ -1 ] wyck = list( groupby( map( int, s[ 2 ].split() ), 2 ) ) gens = [] for l in filter( lambda l: l, s[ 3: ] ): ps = l.split() n = int( ps[ 0 ] ) v = tuple( map( float, ps[ 1: ] ) ) gens.append( ( n, v ) ) gens.reverse() ginf = dict( laue = laue, inv = inv, ngp = ngp, #nsp = nsp, #ngen = ngen,
ls = open('spgrp.dat').readlines() ls = ls[235:] ## drop conversion data exp = re.compile( r'^spgr\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(.*)$') data = [[] for i in xrange(230)] for s in sg(ls): res = exp.match(s[0]) if res: num, snum, laue, inv, ngp, nsp, ngen = map(int, res.groups()[:-1]) symb = res.groups()[-1] wyck = list(groupby(map(int, s[2].split()), 2)) gens = [] for l in filter(lambda l: l, s[3:]): ps = l.split() n = int(ps[0]) v = tuple(map(float, ps[1:])) gens.append((n, v)) gens.reverse() ginf = dict( laue=laue, inv=inv, ngp=ngp, #nsp = nsp,