Skip to content

Commit

Permalink
Merge pull request #21 from nhew1994/python3.6
Browse files Browse the repository at this point in the history
Fix python3.6
  • Loading branch information
Stepan Tsirkin committed Apr 13, 2021
2 parents 039a6f0 + afab77e commit bd3ff1f
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 16 deletions.
10 changes: 5 additions & 5 deletions src/python_interface/bandupy/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ def create_bandup_input(args):
("dE",args.dE)])
with open(energy_info_file, 'w') as f:
f.write(file_header())
for k,v in energy_info_file_contents.iteritems():
for k,v in energy_info_file_contents.items():
f.write("%.5f # %s \n"%(v,k))

# PC, SC and PC-KPT files
Expand Down Expand Up @@ -287,7 +287,7 @@ def create_bandup_input(args):

# Creating/verifying files
# Wavefunction files will not be copied. Symlinks will be made in this case
for source, dest_properties in origin2dest.iteritems():
for source, dest_properties in origin2dest.items():
assert_valid_path(source)
dest = dest_properties['dest']
to_be_copied = dest_properties['copy']
Expand Down Expand Up @@ -349,7 +349,7 @@ def create_bandup_plot_input(args):
("emax",args.emax),
("dE",args.dE)])
with open(energy_info_file, 'w') as f:
for k,v in energy_info_file_contents.iteritems():
for k,v in energy_info_file_contents.items():
f.write("%.5f ! %s \n"%(v,k))

# PC, SC, PC-KPT, and main input files
Expand All @@ -375,7 +375,7 @@ def create_bandup_plot_input(args):

# Creating/verifying files
# Wavefunction files will not be copied. Symlinks will be made in this case
for source, dest_properties in origin2dest.iteritems():
for source, dest_properties in origin2dest.items():
assert_valid_path(source)
dest = dest_properties['dest']
to_be_copied = dest_properties['copy']
Expand Down Expand Up @@ -405,4 +405,4 @@ def create_bandup_plot_input(args):
warnings.warn('File "%s" already exists and will be used! '%(
os.path.basename(dest))+
'Please use "--overwrite" if you want to '+
'overwrite it.')
'overwrite it.')
8 changes: 4 additions & 4 deletions src/python_interface/bandupy/orbital_contributions.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,10 @@ def switch_spin_channel(self):
def bands(self):
if(self._bands[self._current_ispin] is None):
self._bands[self._current_ispin] = (
[{'number':None, 'ener':None, 'occ':None} for ib in xrange(self.nbands)]
[{'number':None, 'ener':None, 'occ':None} for ib in range(self.nbands)]
)
if(self._create_ion_proj_norms_dicts):
for ib in xrange(self.nbands):
for ib in range(self.nbands):
self._bands[self._current_ispin][ib]['ion_proj_norms'] = (
[{orb:None for orb in self.orbitals} for
i in range(self.nions)]
Expand Down Expand Up @@ -216,7 +216,7 @@ def saveinfo(self):
self.current_ispin+1))
if(self.number==1 and self.current_ispin==0):
mkdir(outdir)
pickle_file = open(pickle_file_name, 'w')
pickle_file = open(pickle_file_name, 'wb')
else:
pickle_file = open(pickle_file_name, 'a+b')
mkdir(outdir, ignore_existing=True)
Expand Down Expand Up @@ -278,7 +278,7 @@ def contrib_matrix_element(self, iband1, iband2, orb,
"""

if(selected_ion_indices is None):
selected_ion_indices = xrange(self.nions)
selected_ion_indices = range(self.nions)
iorb = self.orb2iorb(orb)
combined_at_orb_indices = (self.combined_atom_orb_index(iat, iorb=iorb) for
iat in selected_ion_indices)
Expand Down
4 changes: 2 additions & 2 deletions src/python_interface/bandupy/runners.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def run_bandup(args):
os.chdir(args.results_dir)
bandup_run_options = [BANDUP_BIN] + args.argv
with open("out_BandUP.dat", 'w') as f:
bandup_run = Popen(bandup_run_options, stdout=PIPE, stderr=STDOUT)
bandup_run = Popen(bandup_run_options, stdout=PIPE, stderr=STDOUT,encoding='UTF-8')
for line in iter(bandup_run.stdout.readline, ''):
sys.stdout.write(line)
f.write(line)
Expand All @@ -49,7 +49,7 @@ def run_pre_bandup_tool(args):
bandup_pre_unf_run_options = [BANDUP_PRE_UNFOLDING_BIN] + args.argv
with open("out_BandUP_get_SCKPTS_pre_unfolding.dat", 'w') as f:
bandup_pre_unf_run = Popen(bandup_pre_unf_run_options,
stdout=PIPE, stderr=STDOUT)
stdout=PIPE, stderr=STDOUT,encoding='UTF-8')
for line in iter(bandup_pre_unf_run.stdout.readline, ''):
sys.stdout.write(line)
f.write(line)
Expand Down
4 changes: 2 additions & 2 deletions src/python_interface/bandupy/unfolding_density_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,11 @@ def read_unf_dens_ops(
# Combining itertools and the "next" file method to have both
# current and next lines yiedled simultaneously
f, f_one_step_ahead = itertools.tee(udof)
f_one_step_ahead.next()
next(f_one_step_ahead)
f_one_step_ahead = itertools.chain(f_one_step_ahead,[None])

next_line_contains_mat_el = False
for iline, (line, next_line) in enumerate(itertools.izip(f, f_one_step_ahead)):
for iline, (line, next_line) in enumerate(zip(f, f_one_step_ahead)):
if('SpinChannel' in line): spin_channel = int(line.split('=')[-1])
elif('nScBands' in line): nbands = int(line.split('=')[-1])
elif('emin' in line): emin_parent_grid = float(line.split('=')[1].split()[0])
Expand Down
2 changes: 1 addition & 1 deletion src/python_interface/bandupy/vasp.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def try_to_read_procar(fpath=os.path.join(WORKING_DIR, 'PROCAR'),
iatom = 0
reading_real_part = True
comb_iat_iorbs = [kpt.combined_atom_orb_index(iat=iatom,iorb=i)
for i in xrange(kpt.n_orbs_per_atom)]
for i in range(kpt.n_orbs_per_atom)]
if(same_line_real_and_imag_phase):
try:
for i, comb_iat_iorb in enumerate(comb_iat_iorbs):
Expand Down
5 changes: 3 additions & 2 deletions src/python_interface/bandupy/warnings_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
class WarningError(UserWarning):
pass

def _new_showwarning(message, category = UserWarning, filename = '', lineno = -1):
def _new_showwarning(message, category = UserWarning, filename = '',
lineno = -1, msg_file=None, line=None):
if(category==WarningError):
warn_msg = 'ERROR '
else:
Expand All @@ -35,4 +36,4 @@ def _new_showwarning(message, category = UserWarning, filename = '', lineno = -1
sys.exit(1)
warnings.showwarning = _new_showwarning



0 comments on commit bd3ff1f

Please sign in to comment.