Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent N_monomer > 3 in AM algorithm, and fix errors in python tools #18

Merged
merged 1 commit into from
Nov 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/iterate_mod.fp.f90
Original file line number Diff line number Diff line change
Expand Up @@ -1182,6 +1182,9 @@ subroutine iterate_AM( &
+ chi(2,3)*rho(1,k+1) + chi(1,3)*rho(2,k+1) )/N_monomer &!
- omega(alpha,k+1)
end do
else
write(6,*) 'Error: Anderson Mixing is only implemented for N_monomer = 2 or 3'
stop
endif

end do
Expand Down
26 changes: 13 additions & 13 deletions tools/python/pscf/fieldfile.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from io import IO, IoException
from io_pscf import IO, IoException
from version import Version
import string
import sys
Expand Down Expand Up @@ -44,11 +44,11 @@ def __init__(self,filename):
The file named filename is opened and closed within this function.
'''
self.file = open(filename, 'r')
self._io = IO()
file = self.file
self._io = IO()
file = self.file

# Read version line
self.version = Version(self.file)
self.version = Version(self.file)

self._input_unit_cell()
self.group_name = self._input_var('char')
Expand Down Expand Up @@ -85,7 +85,7 @@ def __init__(self,filename):
self.counts.append(int(data[j]))

self.file.close()
self.file = None
self.file = None

def write(self, file, major=1, minor=0):
'''
Expand All @@ -105,9 +105,9 @@ def write(self, file, major=1, minor=0):
file = temp
self.file = file

self.version.major = major
self.version.minor = minor
self.version.write(file)
self.version.major = major
self.version.minor = minor
self.version.write(file)

self._output_unit_cell()
self._output_var('char', 'group_name')
Expand All @@ -123,7 +123,7 @@ def write(self, file, major=1, minor=0):
file.write('%6d' % self.counts[i])
file.write("\n")

file.close()
file.close()
self.file = None

def addMonomer(self, value = 0.0):
Expand Down Expand Up @@ -177,14 +177,14 @@ def _input_vec(self, type, n=None, comment=None, s='R',f='A'):

# Output methods (output by name)
def _output_var(self, type, name, f='A'):
if self.__dict__.has_key(name):
if name in self.__dict__:
data = self.__dict__[name]
self._io.output_var(self.file, type, data, name, f)
self._io.output_var(self.file, type, data, name, f)

def _output_vec(self, type, name, n=None, s='R', f='A'):
if self.__dict__.has_key(name):
if name in self.__dict__:
data = self.__dict__[name]
self._io.output_vec(self.file, type, data, n, name, s, f)
self._io.output_vec(self.file, type, data, n, name, s, f)

def _input_unit_cell(self):
''' Analog of subroutine _input_unit_cell in unit_cell_mod.f '''
Expand Down
26 changes: 13 additions & 13 deletions tools/python/pscf/io.py → tools/python/pscf/io_pscf.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def __init__(self):
"""
Default construct an initially empty object.
"""
self.comment = None
self.comment = None

def input_comment(self, file, comment=None):
"""
Expand Down Expand Up @@ -45,8 +45,8 @@ def input_var(self,file,type,comment=None,f='A'):
-- 'N' -> no comment string
"""
if f == 'A':
if not self.input_comment(file, comment):
return None
if not self.input_comment(file, comment):
return None
data = file.readline().strip()
if type == 'int':
return int(data)
Expand All @@ -60,7 +60,7 @@ def input_var(self,file,type,comment=None,f='A'):
elif data in ['F','false','FALSE','FALSE']:
return 0
else:
raise "Invalid logical variable:", data
raise("Invalid logical variable:", data)
else:
raise 'Illegal type in input_var'

Expand All @@ -78,8 +78,8 @@ def input_vec(self,file,type,n=None, comment=None, s='R', f='A'):
-- 'C' -> column vector (n lines)
"""
if f == 'A':
if not self.input_comment(file,comment):
return None
if not self.input_comment(file,comment):
return None
if s == 'R': # Row Vector
data = file.readline().split()
if n:
Expand Down Expand Up @@ -116,8 +116,8 @@ def input_mat(self, file, type, m, n=None, comment=None, s=None,f='A'):
-- 'L' -> symmetric lower triangular (0 diagonals)
"""
if f == 'A':
if not self.input_comment(file,comment):
return None
if not self.input_comment(file,comment):
return None
# Emulate initialization of m x n array
if not n:
n = m
Expand Down Expand Up @@ -170,8 +170,8 @@ def format_var(self, type, data):
elif type == 'real':
return '%20.10E' % data
elif type == 'char':
data = "'" + data + "'"
return "%20s" % data
data = "'" + data + "'"
return "%20s" % data
elif type == 'logic':
if data:
data = 'T'
Expand Down Expand Up @@ -221,8 +221,8 @@ def output_vec(self, file, type, data, n=None, comment=None, s='R', f='A'):
s -- 'R' -> row vector (one line)
-- 'C' -> column vector (n lines)
"""
if not n:
n = len(data)
if not n:
n = len(data)
if f == 'A':
self.output_comment(file, comment)
for i in range(n):
Expand All @@ -248,7 +248,7 @@ def output_mat(self, file, type, data, m=None, n=None,
-- 'S' -> symmetric
-- 'L' -> symmetric lower triangular (0 diagonals)
"""
if not m:
if not m:
m = len(data)
if not n:
n = m
Expand Down
4 changes: 1 addition & 3 deletions tools/python/pscf/outfile.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
from io import IO, IoException
from io_pscf import IO
from version import Version
from paramfile import ParamFile
import string
import sys

class OutFile(ParamFile):
"""
Expand Down
3 changes: 1 addition & 2 deletions tools/python/pscf/paramfile.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from io import IO, IoException
from io_pscf import IO, IoException
from version import Version
import string
import sys

class ParamFile(object):
"""
Expand Down
2 changes: 1 addition & 1 deletion tools/python/pscf/sweep.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from outfile import OutFile
import sys, os, string
import os, string

class Sweep(object):
"""
Expand Down
13 changes: 5 additions & 8 deletions tools/python/pscf/version.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
from io import IO, IoException
import string

class Version(object):
'''
Abstract representation of a file format version tag
Expand All @@ -16,13 +13,13 @@ def __init__(self,file):
'''

# Read first line to determine file format
line = file.readline().strip()
line = file.readline().strip()
if line == '':
self.major = 0
self.minor = 9
else:
line = line.split()
if line[0] == 'format':
line = line.split()
if line[0] == 'format':
self.major = int(line[1])
self.minor = int(line[2])
else:
Expand All @@ -44,7 +41,7 @@ def eq(self, major, minor):

def ge(self, major, minor):
if (self.major >= major and self.minor >= minor):
return true
return True
else:
return false
return False