1#!/usr/bin/env python
2
3import numpy as np
4import hall2operations as h2o
5import make_Wyckoff_db as wdb
6
7characters = "abcdefghijklmnopqrstuvwxyz"
8
9def get_Hall_operations( hall_file, hall_number ):
10    hall_symbols = h2o.read_spg_csv( hall_file  )
11    return h2o.HallSymbol( hall_symbols[ hall_number - 1 ][0] ).get_full_operations()
12
13def get_wyckoff_position_operators( wyckoff_file, hall_number ):
14    wyckoff = wdb.read_wyckoff_csv( wyckoff_file )
15    operations = wdb.get_wyckoff_positions( wyckoff )
16    return operations[ hall_number - 1 ]
17
18def multiply_operations( spg_op, pos_op ):
19    r, t = spg_op
20    o_r, o_t = pos_op
21    return ( np.dot( r, o_r ), np.dot( o_t, r.T ) + t )
22
23def show_site_symmetries( rotations, translations, operators ):
24    for i, o_site in enumerate( operators ):
25        for j, o in enumerate( o_site ):
26            o_r = o[0]
27            o_t = o[1] / 24.0
28            print "--------- %s, %d ----------" % (characters[len(operators) - i - 1], j+1)
29            for r, t in zip( rotations, translations ):
30                mo = multiply_operations( ( r, t ), ( o_r, o_t ) )
31                diff = mo[1] - o_t
32                if ( mo[0] - o_r == 0 ).all() and ( abs( diff - diff.round() ) < 0.01 ).all():
33                    print r, t
34
35
36if __name__ == '__main__':
37    from optparse import OptionParser
38    parser = OptionParser()
39    parser.set_defaults( is_site = False )
40    parser.add_option("--site", dest="is_site",
41                      action="store_true",
42                      help="Show site symmetries")
43    (options, args) = parser.parse_args()
44
45    rotations, translations = get_Hall_operations( args[0], int( args[2] ) )
46    operators = get_wyckoff_position_operators( args[1], int( args[2] ) )
47
48
49    if options.is_site:
50        show_site_symmetries( rotations, translations, operators )
51