Skip to content
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion examples/AB_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def main():
parameters['E_react'] = {'value': 0.9}


for key, value in parameters.iteritems():
for key, value in parameters.items():
pt.add_parameter(name=key, **value)


Expand Down
10 changes: 5 additions & 5 deletions kmos/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def evaluate_rate_expression(rate_expr, parameters={}):
parameters = [Parameter(), ... ]
"""
import tokenize
import StringIO
from io import StringIO
import math
from kmos import units

Expand All @@ -90,10 +90,10 @@ def evaluate_rate_expression(rate_expr, parameters={}):
replaced_tokens = []

# replace some aliases
for old, new in rate_aliases.iteritems():
for old, new in rate_aliases.items():
rate_expr = rate_expr.replace(old, new)
try:
input = StringIO.StringIO(rate_expr).readline
input = StringIO(rate_expr).readline
tokens = list(tokenize.generate_tokens(input))
except:
raise Exception('Could not tokenize expression: %s' % input)
Expand All @@ -103,7 +103,7 @@ def evaluate_rate_expression(rate_expr, parameters={}):
elif token in dir(units):
replaced_tokens.append((i, str(eval('units.' + token))))
elif token.startswith('m_'):
from ase.atoms import string2symbols
from ase.symbols import string2symbols
from ase.data import atomic_masses
from ase.data import atomic_numbers
species_name = '_'.join(token.split('_')[1:])
Expand Down Expand Up @@ -146,7 +146,7 @@ def evaluate_rate_expression(rate_expr, parameters={}):
rate_expr = tokenize.untokenize(replaced_tokens)
try:
rate_const = eval(rate_expr)
except Exception, e:
except Exception as e:
raise UserWarning(
"Could not evaluate rate expression: %s\nException: %s" \
% (rate_expr, e))
Expand Down
62 changes: 35 additions & 27 deletions kmos/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,12 @@
# You should have received a copy of the GNU General Public License
# along with kmos. If not, see <http://www.gnu.org/licenses/>.

from __future__ import with_statement
import logging
import os
import shutil

logger = logging.getLogger(__name__)

usage = {}
usage['all'] = """kmos help all
Display documentation for all commands.
Expand Down Expand Up @@ -212,13 +214,19 @@ def get_options(args=None, get_parser=False):
default=False,
)

try:
from numpy.distutils.fcompiler import get_default_fcompiler
from numpy.distutils import log
log.set_verbosity(-1, True)
fcompiler = get_default_fcompiler()
except:
fcompiler = 'gfortran'
# Detect available Fortran compiler
# Note: numpy.distutils is deprecated and removed in Python >= 3.12
# Using direct detection instead
import shutil
fcompiler = 'gnu95' # Default: gnu95 is the f2py name for gfortran

# Try to detect available Fortran compiler
if shutil.which('gfortran'):
fcompiler = 'gnu95'
elif shutil.which('ifort'):
fcompiler = 'intel'
elif shutil.which('ifx'):
fcompiler = 'intelem'

parser.add_option('-f', '--fcompiler',
dest='fcompiler',
Expand Down Expand Up @@ -287,9 +295,9 @@ def main(args=None):
model.do_steps(nsteps)

needed_time = time() - time0
print('Using the [%s] backend.' % model.get_backend())
print('%s steps took %.2f seconds' % (nsteps, needed_time))
print('Or %.2e steps/s' % (1e6 / needed_time))
logger.info('Using the [%s] backend.' % model.get_backend())
logger.info('%s steps took %.2f seconds' % (nsteps, needed_time))
logger.info('Or %.2e steps/s' % (1e6 / needed_time))
model.deallocate()
elif args[0] == 'build':
from kmos.utils import build
Expand All @@ -306,7 +314,7 @@ def main(args=None):
parser.error('XML file and export path expected.')
if len(args) < 3:
out_dir = '%s_%s' % (os.path.splitext(args[1])[0], options.backend)
print('No export path provided. Exporting to %s' % out_dir)
logger.info('No export path provided. Exporting to %s' % out_dir)
args.append(out_dir)

xml_file = args[1]
Expand All @@ -326,7 +334,7 @@ def main(args=None):
if len(args) < 3:
out_dir = '%s_%s' % (os.path.splitext(args[1])[0], options.backend)

print('No export path provided. Exporting to %s' % out_dir)
logger.info('No export path provided. Exporting to %s' % out_dir)
args.append(out_dir)

xml_file = args[1]
Expand All @@ -352,14 +360,14 @@ def main(args=None):
if options.overwrite :
overwrite = 'y'
else:
overwrite = raw_input(('Should I overwrite existing %s ?'
overwrite = input(('Should I overwrite existing %s ?'
'[y/N] ') % out).lower()
if overwrite.startswith('y') :
print('Overwriting {out}'.format(**locals()))
logger.info('Overwriting {out}'.format(**locals()))
os.remove('../%s' % out)
shutil.move(out, '..')
else :
print('Skipping {out}'.format(**locals()))
logger.info('Skipping {out}'.format(**locals()))
else:
shutil.move(out, '..')

Expand All @@ -368,7 +376,7 @@ def main(args=None):
pt = kmos.io.import_file(args[1])
if len(args) < 3:
out_dir = os.path.splitext(args[1])[0]
print('No export path provided. Exporting kmc_settings.py to %s'
logger.info('No export path provided. Exporting kmc_settings.py to %s'
% out_dir)
args.append(out_dir)

Expand All @@ -384,12 +392,12 @@ def main(args=None):
parser.error('Which help do you want?')
if args[1] == 'all':
for command in sorted(usage):
print(usage[command])
logger.info(usage[command])
elif args[1] in usage:
print('Usage: %s\n' % usage[args[1]])
logger.info('Usage: %s\n' % usage[args[1]])
else:
arg = match_keys(args[1], usage, parser)
print('Usage: %s\n' % usage[arg])
logger.info('Usage: %s\n' % usage[arg])

elif args[0] == 'import':
import kmos.io
Expand All @@ -403,10 +411,10 @@ def main(args=None):

elif args[0] == 'rebuild':
from time import sleep
print('Will rebuild model from kmc_settings.py in current directory')
print('Please do not interrupt,'
logger.info('Will rebuild model from kmc_settings.py in current directory')
logger.info('Please do not interrupt,'
' build process, as you will most likely')
print('loose the current model files.')
logger.info('loose the current model files.')
sleep(2.)
from sys import path
path.append(os.path.abspath(os.curdir))
Expand Down Expand Up @@ -456,17 +464,17 @@ def main(args=None):
try:
model = KMC_Model(print_rates=False)
except:
print("Warning: could not import kmc_model!"
logger.info("Warning: could not import kmc_model!"
" Please make sure you are in the right directory")
sh(banner='Note: model = KMC_Model(print_rates=False){catmap_message}'.format(**locals()))
try:
model.deallocate()
except:
print("Warning: could not deallocate model. Was is allocated?")
logger.info("Warning: could not deallocate model. Was is allocated?")

elif args[0] == 'version':
from kmos import VERSION
print(VERSION)
logger.info(VERSION)

elif args[0] == 'view':
from sys import path
Expand All @@ -479,7 +487,7 @@ def main(args=None):
path.append(os.path.abspath(os.curdir))
from kmos.run import KMC_Model
model = KMC_Model(banner=False, print_rates=False)
print(model.xml())
logger.info(model.xml())

else:
parser.error('Command "%s" not understood.' % args[0])
Expand Down
2 changes: 1 addition & 1 deletion kmos/fortran_src/assert.ppc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifdef DEBUG
#define ASSERT(a, r) if(.not.(a))call assertion_fail(#a ,r)
#define ASSERT(a, r) if(.not.(a))call assertion_fail("assertion failed" ,r)
#else
#define ASSERT(a, r)
#endif
15 changes: 7 additions & 8 deletions kmos/fortran_src/base.mpy
Original file line number Diff line number Diff line change
Expand Up @@ -640,8 +640,7 @@
#@ integ_rates(i)=integ_rates(i)+nr_of_sites(i)*rates(i)*kmc_time_step
#@ enddo
#@
#@ ASSERT(accum_rates(nr_of_proc).gt.0.,"base/update_accum_rate found" // &
#@ "accum_rates(nr_of_proc)=0, so no process is available at all")
#@ ASSERT(accum_rates(nr_of_proc).gt.0.,"base/update_accum_rate: no process available")
#@
#@ end subroutine update_integ_rate
#@ !------ S. Matera 09/18/2012------
Expand Down Expand Up @@ -802,20 +801,20 @@
#@ end subroutine deallocate_system
#@
#@
#@ pure function get_system_name()
#@ subroutine get_system_name(output_system_name)
#@ !****f* base/get_system_name
#@ ! FUNCTION
#@ ! Return the systems name, that was specified with base/allocate_system
#@ !
#@ ! ARGUMENTS
#@ !
#@ ! * ``system_name`` Writeable string of type character(len=200).
#@ ! * ``output_system_name`` Writeable string of type character(len=200).
#@ !******
#@ !---------------I/O variables---------------
#@ character(len=200) :: get_system_name
#@
#@ get_system_name = system_name
#@ end function get_system_name
#@ character(len=200), intent(out) :: output_system_name
#@
#@ output_system_name = system_name
#@ end subroutine get_system_name
#@
#@
#@ subroutine set_system_name(input_system_name)
Expand Down
13 changes: 6 additions & 7 deletions kmos/fortran_src/base_lat_int.mpy
Original file line number Diff line number Diff line change
Expand Up @@ -651,8 +651,7 @@ nr_of_species_m1 = nr_of_species - 1
#@ integ_rates(i)=integ_rates(i)+nr_of_sites(i)*rates(i)*kmc_time_step
#@ enddo
#@
#@ ASSERT(accum_rates(nr_of_proc).gt.0.,"base/update_accum_rate found"// &
#@ "accum_rates(nr_of_proc)=0, so no process is available at all")
#@ ASSERT(accum_rates(nr_of_proc).gt.0.,"base/update_accum_rate: no process available")
#@
#@ end subroutine update_integ_rate
#@ !------ S. Matera 09/18/2012------
Expand Down Expand Up @@ -813,20 +812,20 @@ nr_of_species_m1 = nr_of_species - 1
#@ end subroutine deallocate_system
#@
#@
#@ pure function get_system_name()
#@ subroutine get_system_name(output_system_name)
#@ !****f* base/get_system_name
#@ ! FUNCTION
#@ ! Return the systems name, that was specified with base/allocate_system
#@ !
#@ ! ARGUMENTS
#@ !
#@ ! * ``system_name`` Writeable string of type character(len=200).
#@ ! * ``output_system_name`` Writeable string of type character(len=200).
#@ !******
#@ !---------------I/O variables---------------
#@ character(len=200) :: get_system_name
#@ character(len=200), intent(out) :: output_system_name
#@
#@ get_system_name = system_name
#@ end function get_system_name
#@ output_system_name = system_name
#@ end subroutine get_system_name
#@
#@
#@ subroutine set_system_name(input_system_name)
Expand Down
13 changes: 6 additions & 7 deletions kmos/fortran_src/base_otf.f90
Original file line number Diff line number Diff line change
Expand Up @@ -733,8 +733,7 @@ subroutine update_integ_rate()
integ_rates(i)=integ_rates(i)+rates_matrix(i,volume+1)*kmc_time_step
enddo

ASSERT(accum_rates(nr_of_proc).gt.0.,"base/update_accum_rate found"// &
"accum_rates(nr_of_proc)=0, so no process is available at all")
ASSERT(accum_rates(nr_of_proc).gt.0.,"base/update_accum_rate: no process available")

end subroutine update_integ_rate
!------ S. Matera 09/18/2012------
Expand Down Expand Up @@ -933,20 +932,20 @@ subroutine deallocate_system()
end subroutine deallocate_system


pure function get_system_name()
subroutine get_system_name(output_system_name)
!****f* base/get_system_name
! FUNCTION
! Return the systems name, that was specified with base/allocate_system
!
! ARGUMENTS
!
! * ``system_name`` Writeable string of type character(len=200).
! * ``output_system_name`` Writeable string of type character(len=200).
!******
!---------------I/O variables---------------
character(len=200) :: get_system_name
character(len=200), intent(out) :: output_system_name

get_system_name = system_name
end function get_system_name
output_system_name = system_name
end subroutine get_system_name


subroutine set_system_name(input_system_name)
Expand Down
16 changes: 8 additions & 8 deletions kmos/gui/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

# standard modules
import optparse
import StringIO
from io import StringIO
import sys
import os

Expand Down Expand Up @@ -77,17 +77,17 @@
def verbose(func):
"""Debugging helper that allows to track input and output of function
via decoration"""
print >> sys.stderr, "monitor %r" % (func.func_name)
print("monitor %r" % (func.__name__), file=sys.stderr)

def wrapper_func(*args, **kwargs):
"""The wrapping function
"""
print >> sys.stderr, "call(\033[0;31m%s.%s\033[0;30m): %r\n" % \
(type(args[0]).__name__, func.func_name, args[1:]), \
sys.stderr.flush()
print("call(\033[0;31m%s.%s\033[0;30m): %r\n" %
(type(args[0]).__name__, func.__name__, args[1:]), file=sys.stderr)
sys.stderr.flush()
ret = func(*args, **kwargs)
print >> sys.stderr, " ret(%s): \033[0;32m%r\033[0;30m\n" % \
(func.func_name, ret)
print(" ret(%s): \033[0;32m%r\033[0;30m\n" %
(func.__name__, ret), file=sys.stderr)
return ret
return wrapper_func

Expand Down Expand Up @@ -484,7 +484,7 @@ def __init__(self):
self.menubar.insert_action_group(actions, 0)
try:
mergeid = self.menubar.add_ui_from_string(menu_layout)
except gobject.GError, error:
except gobject.GError as error:
print('Building menu failed: %s, %s' % (error, mergeid))

# Initialize the project tree, passing in the menu bar
Expand Down
Loading