Skip to content

Commit

Permalink
Merge pull request #234 from e-kwsm/pep8
Browse files Browse the repository at this point in the history
PEP8 fixes
  • Loading branch information
evaleev authored Dec 29, 2022
2 parents 8405701 + df8cb26 commit a8c8d6b
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 26 deletions.
9 changes: 5 additions & 4 deletions export/fortran/c_to_f.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@
c_to_f.py <C input file> <Fortran output file> <C struct name(s)>
'''

import re, sys
import re
import sys

def extract_c_struct_fields(c_code, struct_name):
struct_re = re.compile("^\s*typedef\s*struct\s*\{([^\}]*)\}\s*"+struct_name+"\s*;",re.MULTILINE | re.DOTALL)
struct_re = re.compile(r"^\s*typedef\s*struct\s*\{([^\}]*)\}\s*"+struct_name+r"\s*;",re.MULTILINE | re.DOTALL)
m = struct_re.search(c_code)
if not m: return []
fields = m.group(1).splitlines()
Expand All @@ -26,7 +27,7 @@ def parse_c_struct_fields(fields):
for f in fields:
words = f.split()
var = words.pop()
m = re.match("(\w*)(?:\[(\w+)\])?", var)
m = re.match(r"(\w*)(?:\[(\w+)\])?", var)
name.append(m.group(1))
size.append(m.group(2))
dtype.append(' '.join(words))
Expand Down Expand Up @@ -77,4 +78,4 @@ def convert_type_c_to_f(dtype):
f_out.write("end type\n")

c_in.close()
f_out.close()
f_out.close()
3 changes: 2 additions & 1 deletion export/fortran/make_defs.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import re, sys
import re
import sys
f_in = open(sys.argv[1], 'r')
f_out = open(sys.argv[2], 'w')
for line in f_in:
Expand Down
3 changes: 2 additions & 1 deletion python/setup.py.in
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import setuptools
from setuptools import setup, Extension
from setuptools.command.build_ext import build_ext
import os, subprocess
import os
import subprocess

# sources+tests
os.sys.path.append("@PROJECT_SOURCE_DIR@")
Expand Down
37 changes: 20 additions & 17 deletions tests/hartree-fock/hartree-fock++-validate.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
from __future__ import print_function
import sys, re, math, os
import math
import os
import re
import sys

def pat_numbers(n):
result = ''
for i in range(n):
result += '\s*([+-e\d.]+)'
result += r'\s*([+-e\d.]+)'
return result

def validate(label, data, refdata, tolerance, textline):
Expand Down Expand Up @@ -107,21 +110,21 @@ def validate(label, data, refdata, tolerance, textline):
Hok = False if LIBINT_ONEBODY_DERIV>1 and LIBINT_ERI_DERIV>1 else True

for line in instr:
match1 = re.match('\*\* Hartree-Fock energy =' + pat_numbers(1), line)
match2 = re.match('\*\* edipole =' + pat_numbers(3), line)
match3 = re.match('\*\* equadrupole =' + pat_numbers(6), line)
match4 = re.match('\*\* 1-body forces =' + pat_numbers(9), line)
match5 = re.match('\*\* Pulay forces =' + pat_numbers(9), line)
match6 = re.match('\*\* 2-body forces =' + pat_numbers(9), line)
match7 = re.match('\*\* nuclear repulsion forces =' + pat_numbers(9), line)
match8 = re.match('\*\* Hartree-Fock forces =' + pat_numbers(9), line)
match9 = re.match('\*\* 1-body hessian =' + pat_numbers(45), line)
match10 = re.match('\*\* Pulay hessian =' + pat_numbers(45), line)
match11 = re.match('\*\* 2-body hessian =' + pat_numbers(45), line)
match12 = re.match('\*\* nuclear repulsion hessian =' + pat_numbers(45), line)
match13 = re.match('\*\* Hartree-Fock hessian =' + pat_numbers(45), line)
match14 = re.match('\*\* sph edipole =' + pat_numbers(3), line)
match15 = re.match('\*\* sph equadrupole =' + pat_numbers(5), line)
match1 = re.match(r'\*\* Hartree-Fock energy =' + pat_numbers(1), line)
match2 = re.match(r'\*\* edipole =' + pat_numbers(3), line)
match3 = re.match(r'\*\* equadrupole =' + pat_numbers(6), line)
match4 = re.match(r'\*\* 1-body forces =' + pat_numbers(9), line)
match5 = re.match(r'\*\* Pulay forces =' + pat_numbers(9), line)
match6 = re.match(r'\*\* 2-body forces =' + pat_numbers(9), line)
match7 = re.match(r'\*\* nuclear repulsion forces =' + pat_numbers(9), line)
match8 = re.match(r'\*\* Hartree-Fock forces =' + pat_numbers(9), line)
match9 = re.match(r'\*\* 1-body hessian =' + pat_numbers(45), line)
match10 = re.match(r'\*\* Pulay hessian =' + pat_numbers(45), line)
match11 = re.match(r'\*\* 2-body hessian =' + pat_numbers(45), line)
match12 = re.match(r'\*\* nuclear repulsion hessian =' + pat_numbers(45), line)
match13 = re.match(r'\*\* Hartree-Fock hessian =' + pat_numbers(45), line)
match14 = re.match(r'\*\* sph edipole =' + pat_numbers(3), line)
match15 = re.match(r'\*\* sph equadrupole =' + pat_numbers(5), line)
if match1:
eok = validate("HF energy", match1.groups(), eref, etol, line)
elif match2:
Expand Down
8 changes: 5 additions & 3 deletions tests/hartree-fock/hartree-fock-validate.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from __future__ import print_function
import sys, re, math
import math
import re
import sys

# first arg is the input file, if missing read sys.stdin
try:
Expand All @@ -14,7 +16,7 @@
returncode = 1
for line in instr:
print(line,end="")
x = re.match('\*\* Hartree-Fock energy =\s*([-\d.]+)', line)
x = re.match(r'\*\* Hartree-Fock energy =\s*([-\d.]+)', line)
if x:
efound_str = x.group(1)
if (math.fabs(eref - float(efound_str)) < tol):
Expand All @@ -24,4 +26,4 @@
if len(sys.argv) > 1:
instr.close()

sys.exit(returncode)
sys.exit(returncode)

0 comments on commit a8c8d6b

Please sign in to comment.