<s> import os <EOL> import shutil <EOL> import numpy as np <EOL> import tempfile <EOL> import subprocess <EOL> from . sfminittypes import EG , write_EGs_file , read_rot_file <EOL> def solve_global_rotations ( indices , pairwise_rotations , cc = None ) : <EOL> """<STR_LIT>""" <EOL> ROT_SOLVER_DIR = os . path . abspath ( os . path . join ( <EOL> os . path . dirname ( __file__ ) , '<STR_LIT:..>' , '<STR_LIT>' ) ) <EOL> tmpdir = tempfile . mkdtemp ( ) <EOL> ccfile = os . path . join ( tmpdir , '<STR_LIT>' ) <EOL> np . savetxt ( ccfile , cc , fmt = '<STR_LIT>' ) <EOL> egfile = os . path . join ( tmpdir , '<STR_LIT>' ) <EOL> EGs = [ ] <EOL> for ( i , j ) , Rij in zip ( indices , pairwise_rotations ) : <EOL> EGs . append ( EG ( i , j , Rij , np . zeros ( ( <NUM_LIT:3> , <NUM_LIT:1> ) ) ) ) <EOL> write_EGs_file ( egfile , EGs ) <EOL> log = os . path . join ( tmpdir , '<STR_LIT>' ) <EOL> rotfile = os . path . join ( tmpdir , '<STR_LIT>' ) <EOL> with open ( os . devnull , '<STR_LIT:wb>' ) as devnul : <EOL> subprocess . call ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , log , '<STR_LIT>' , <EOL> "<STR_LIT>" + <EOL> "<STR_LIT>" . format ( egfile , rotfile , ccfile ) + <EOL> "<STR_LIT>" + <EOL> "<STR_LIT>" + <EOL> "<STR_LIT>" + <EOL> "<STR_LIT>" ] , <EOL> cwd = ROT_SOLVER_DIR , stdout = devnul , stderr = devnul ) <EOL> if not os . path . exists ( rotfile ) : <EOL> print '<STR_LIT>' <EOL> print '<STR_LIT>' <EOL> with open ( log , '<STR_LIT:r>' ) as fin : <EOL> print fin . read ( ) <EOL> shutil . rmtree ( tmpdir ) <EOL> raise Exception ( "<STR_LIT>" ) <EOL> ind , R = read_rot_file ( rotfile ) <EOL> shutil . rmtree ( tmpdir ) <EOL> return ind , R </s>
