diff --git a/common/lib/chem/chem/chemcalc.py b/common/lib/chem/chem/chemcalc.py index 196c99ae5c..81c71177ea 100644 --- a/common/lib/chem/chem/chemcalc.py +++ b/common/lib/chem/chem/chemcalc.py @@ -1,11 +1,14 @@ -from __future__ import division - +from __future__ import absolute_import, division from fractions import Fraction import markupsafe import nltk from nltk.tree import Tree from pyparsing import Literal, OneOrMore, ParseException, StringEnd +from six.moves import map +from six.moves import range +from six.moves import zip +from functools import reduce ARROWS = ('<->', '->') @@ -22,10 +25,10 @@ elements = ['Ac', 'Ag', 'Al', 'Am', 'Ar', 'As', 'At', 'Au', 'B', 'Ba', 'Be', 'Ru', 'S', 'Sb', 'Sc', 'Se', 'Sg', 'Si', 'Sm', 'Sn', 'Sr', 'Ta', 'Tb', 'Tc', 'Te', 'Th', 'Ti', 'Tl', 'Tm', 'U', 'Uuo', 'Uup', 'Uus', 'Uut', 'V', 'W', 'Xe', 'Y', 'Yb', 'Zn', 'Zr'] -digits = map(str, range(10)) +digits = list(map(str, list(range(10)))) symbols = list("[](){}^+-/") phases = ["(s)", "(l)", "(g)", "(aq)"] -tokens = reduce(lambda a, b: a ^ b, map(Literal, elements + digits + symbols + phases)) +tokens = reduce(lambda a, b: a ^ b, list(map(Literal, elements + digits + symbols + phases))) tokenizer = OneOrMore(tokens) + StringEnd() # HTML, Text are temporarily copied from openedx.core.djangolib.markup @@ -263,7 +266,7 @@ def _get_final_tree(s): try: tokenized = tokenizer.parseString(s) parsed = parser.parse(tokenized) - merged = _merge_children(parsed.next(), {'S', 'group'}) + merged = _merge_children(next(parsed), {'S', 'group'}) final = _clean_parse_tree(merged) return final except StopIteration: @@ -354,11 +357,11 @@ def divide_chemical_expression(s1, s2, ignore_state=False): # order of factors and phases must mirror the order of multimolecules, # use 'decorate, sort, undecorate' pattern - treedic['1 cleaned_mm_list'], treedic['1 factors'], treedic['1 phases'] = zip( - *sorted(zip(treedic['1 cleaned_mm_list'], treedic['1 factors'], treedic['1 phases']))) + treedic['1 cleaned_mm_list'], treedic['1 factors'], treedic['1 phases'] = list(zip( + *sorted(zip(treedic['1 cleaned_mm_list'], treedic['1 factors'], treedic['1 phases'])))) - treedic['2 cleaned_mm_list'], treedic['2 factors'], treedic['2 phases'] = zip( - *sorted(zip(treedic['2 cleaned_mm_list'], treedic['2 factors'], treedic['2 phases']))) + treedic['2 cleaned_mm_list'], treedic['2 factors'], treedic['2 phases'] = list(zip( + *sorted(zip(treedic['2 cleaned_mm_list'], treedic['2 factors'], treedic['2 phases'])))) # check if expressions are correct without factors if not _check_equality(treedic['1 cleaned_mm_list'], treedic['2 cleaned_mm_list']): diff --git a/common/lib/chem/chem/chemtools.py b/common/lib/chem/chem/chemtools.py index acb86a6b3a..19405bdcad 100644 --- a/common/lib/chem/chem/chemtools.py +++ b/common/lib/chem/chem/chemtools.py @@ -3,6 +3,7 @@ Also, may be this module is the place for other chemistry-related grade functions. TODO: discuss it. """ +from __future__ import absolute_import import itertools import json import unittest diff --git a/common/lib/chem/chem/miller.py b/common/lib/chem/chem/miller.py index 5f8fca7df2..c0b5868cf4 100644 --- a/common/lib/chem/chem/miller.py +++ b/common/lib/chem/chem/miller.py @@ -1,11 +1,15 @@ """ Calculation of Miller indices """ +from __future__ import absolute_import import decimal import fractions as fr import json import math import numpy as np +from six.moves import map +from six.moves import range +from functools import reduce def lcm(a, b): @@ -101,7 +105,7 @@ def sub_miller(segments): fract.numerator * math.fabs(common_denominator) / fract.denominator for fract in fracts ]) - return'(' + ','.join(map(str, map(decimal.Decimal, miller_indices))) + ')' + return'(' + ','.join(map(str, list(map(decimal.Decimal, miller_indices)))) + ')' def miller(points): @@ -147,7 +151,7 @@ def miller(points): N = np.cross(points[1] - points[0], points[2] - points[0]) O = np.array([0, 0, 0]) P = points[0] # point of plane - Ccs = map(np.array, [[1.0, 0, 0], [0, 1.0, 0], [0, 0, 1.0]]) + Ccs = list(map(np.array, [[1.0, 0, 0], [0, 1.0, 0], [0, 0, 1.0]])) segments = ([ np.dot(P - O, N) / np.dot(ort, N) if np.dot(ort, N) != 0 else np.nan for ort in Ccs @@ -256,7 +260,7 @@ def grade(user_input, correct_answer): if user_answer['lattice'] != correct_answer['lattice']: return False - points = [map(float, p) for p in user_answer['points']] + points = [list(map(float, p)) for p in user_answer['points']] if len(points) < 3: return False diff --git a/common/lib/chem/chem/tests.py b/common/lib/chem/chem/tests.py index 2ed646aea9..848859e6ff 100644 --- a/common/lib/chem/chem/tests.py +++ b/common/lib/chem/chem/tests.py @@ -1,4 +1,4 @@ -from __future__ import print_function +from __future__ import absolute_import, print_function import codecs import unittest from fractions import Fraction diff --git a/common/lib/chem/setup.py b/common/lib/chem/setup.py index 12f8bddefd..dc06d8037b 100644 --- a/common/lib/chem/setup.py +++ b/common/lib/chem/setup.py @@ -1,3 +1,4 @@ +from __future__ import absolute_import from setuptools import setup setup(