9
1
mirror of https://github.com/QuantumPackage/qp2.git synced 2024-12-12 14:43:29 +01:00

Moving to Python3.

This commit is contained in:
Anthony Scemama 2020-01-27 22:30:01 +01:00
parent c50707568c
commit c22daadf40
6 changed files with 83 additions and 84 deletions

View File

@ -1,4 +1,4 @@
#!/usr/bin/env python2
#!/usr/bin/env python3
"""
convert output of GAMESS/GAU$$IAN to ezfio
@ -22,7 +22,7 @@ try:
QP_ROOT = os.environ["QP_ROOT"]
QP_EZFIO = os.environ["QP_EZFIO"]
except KeyError:
print "Error: QP_ROOT environment variable not found."
print("Error: QP_ROOT environment variable not found.")
sys.exit(1)
else:
sys.path = [QP_EZFIO + "/Python",
@ -30,10 +30,11 @@ else:
QP_ROOT + "/install",
QP_ROOT + "/scripts"] + sys.path
from resultsFile import *
try:
from resultsFile import *
except:
print "Error: resultsFile Python library not installed"
print("Error: resultsFile Python library not installed")
sys.exit(1)
@ -48,17 +49,17 @@ def write_ezfio(res, filename):
# |_ | _ _ _|_ ._ _ ._ _
# |_ | (/_ (_ |_ | (_) | | _>
#
print "Electrons\t...\t",
print("Electrons\t...\t", end=' ')
ezfio.set_electrons_elec_alpha_num(res.num_alpha)
ezfio.set_electrons_elec_beta_num(res.num_beta)
print "OK"
print("OK")
#
# |\ | _ | _ o
# | \| |_| (_ | (/_ |
#
print "Nuclei\t\t...\t",
print("Nuclei\t\t...\t", end=' ')
# ~#~#~#~ #
# I n i t #
# ~#~#~#~ #
@ -93,24 +94,23 @@ def write_ezfio(res, filename):
# Transformt H1 into H
import re
p = re.compile(ur'(\d*)$')
p = re.compile(r'(\d*)$')
label = [p.sub("", x.name).capitalize() for x in res.geometry]
ezfio.set_nuclei_nucl_label(label)
ezfio.set_nuclei_nucl_coord(coord_x + coord_y + coord_z)
print "OK"
print("OK")
# _
# /\ _ _ |_) _. _ o _
# /--\ (_) _> |_) (_| _> | _>
#
print "AOS\t\t...\t",
print("AOS\t\t...\t", end=' ')
# ~#~#~#~ #
# I n i t #
# ~#~#~#~ #
import string
at = []
num_prim = []
power_x = []
@ -131,9 +131,9 @@ def write_ezfio(res, filename):
at.append(i + 1)
num_prim.append(len(b.prim))
s = b.sym
power_x.append(string.count(s, "x"))
power_y.append(string.count(s, "y"))
power_z.append(string.count(s, "z"))
power_x.append(str.count(s, "x"))
power_y.append(str.count(s, "y"))
power_z.append(str.count(s, "z"))
coefficient.append(b.coef)
exponent.append([p.expo for p in b.prim])
@ -175,14 +175,14 @@ def write_ezfio(res, filename):
ezfio.set_ao_basis_ao_expo(expo)
ezfio.set_ao_basis_ao_basis("Read by resultsFile")
print "OK"
print("OK")
# _
# |\/| _ _ |_) _. _ o _
# | | (_) _> |_) (_| _> | _>
#
print "MOS\t\t...\t",
print("MOS\t\t...\t", end=' ')
# ~#~#~#~ #
# I n i t #
# ~#~#~#~ #
@ -205,9 +205,9 @@ def write_ezfio(res, filename):
virtual = []
active = [(allMOs[i].eigenvalue, i) for i in range(len(allMOs))]
closed = map(lambda x: x[1], closed)
active = map(lambda x: x[1], active)
virtual = map(lambda x: x[1], virtual)
closed = [x[1] for x in closed]
active = [x[1] for x in active]
virtual = [x[1] for x in virtual]
MOindices = closed + active + virtual
MOs = []
@ -223,7 +223,7 @@ def write_ezfio(res, filename):
MOmap[i] = MOindices.index(i)
energies = []
for i in xrange(mo_num):
for i in range(mo_num):
energies.append(MOs[i].eigenvalue)
if res.occ_num is not None:
@ -237,11 +237,11 @@ def write_ezfio(res, filename):
MoMatrix = []
sym0 = [i.sym for i in res.mo_sets[MO_type]]
sym = [i.sym for i in res.mo_sets[MO_type]]
for i in xrange(len(sym)):
for i in range(len(sym)):
sym[MOmap[i]] = sym0[i]
MoMatrix = []
for i in xrange(len(MOs)):
for i in range(len(MOs)):
m = MOs[i]
for coef in m.vector:
MoMatrix.append(coef)
@ -256,10 +256,10 @@ def write_ezfio(res, filename):
ezfio.set_mo_basis_mo_num(mo_num)
ezfio.set_mo_basis_mo_occ(OccNum)
ezfio.set_mo_basis_mo_coef(MoMatrix)
print "OK"
print("OK")
print "Pseudos\t\t...\t",
print("Pseudos\t\t...\t", end=' ')
try:
lmax = 0
nucl_charge_remove = []
@ -327,7 +327,7 @@ def write_ezfio(res, filename):
else:
ezfio.set_pseudo_do_pseudo(True)
print "OK"
print("OK")
@ -354,15 +354,15 @@ if __name__ == '__main__':
except:
raise
else:
print FILE, 'recognized as', str(RES_FILE).split('.')[-1].split()[0]
print(FILE, 'recognized as', str(RES_FILE).split('.')[-1].split()[0])
write_ezfio(RES_FILE, EZFIO_FILE)
sys.stdout.flush()
if os.system("qp_run save_ortho_mos "+EZFIO_FILE) != 0:
print """Warning: You need to run
print("""Warning: You need to run
qp run save_ortho_mos
to be sure your MOs will be orthogonal, which is not the case when
the MOs are read from output files (not enough precision in output)."""
the MOs are read from output files (not enough precision in output).""")

View File

@ -1,4 +1,4 @@
#!/usr/bin/env python2
#!/usr/bin/env python3
"""
@ -49,7 +49,7 @@ import os.path
try:
import qp_path
except ImportError:
print "source .quantum_package.rc"
print("source .quantum_package.rc")
raise
from docopt import docopt
@ -102,7 +102,7 @@ def main(arguments):
mo_num = ezfio.mo_basis_mo_num
if arguments["--query"]:
print n_frozen
print(n_frozen)
sys.exit(0)
if n_frozen == 0:

View File

@ -0,0 +1,46 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
# C extensions
*.so
# Distribution / packaging
.Python
env/
build/
develop-eggs/
dist/
downloads/
eggs/
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.cache
nosetests.xml
coverage.xml
# Translations
*.mo
*.pot
# Django stuff:
*.log
# Sphinx documentation
docs/_build/
# PyBuilder
target/

View File

@ -21,10 +21,6 @@ let () =
doc="Downloads the EZFIO directory." ;
arg=Without_arg; } ;
{ short='v' ; long="verbose" ; opt=Optional ;
doc="Prints the transfer speed." ;
arg=Without_arg; } ;
anonymous
"(EZFIO_DIR|ADDRESS)"
Mandatory
@ -47,11 +43,6 @@ let () =
ADDRESS x
in
let verbose =
Command_line.get_bool "verbose"
in
let localhost =
Lazy.force TaskServer.ip_address
@ -155,45 +146,6 @@ let () =
Zmq.Socket.subscribe socket_in "";
(*
let action =
if verbose then
begin
match req_or_sub with
| REQ -> (fun () ->
let msg =
Zmq.Socket.recv_all socket_in
in
let t0 = Unix.gettimeofday () in
Zmq.Socket.send_all socket_out msg;
let in_size =
float_of_int ( List.fold_left (fun accu x -> accu + String.length x) 0 msg )
/. 8192. /. 1024.
in
let msg =
Zmq.Socket.recv_all socket_out
in
let t1 = Unix.gettimeofday () in
Zmq.Socket.send_all socket_in msg;
let in_time = t1 -. t0 in
in_time_sum := !in_time_sum +. in_time;
in_size_sum := !in_size_sum +. in_size;
Printf.printf " %16.2f MiB/s -- %16.2f MiB/s\n%!" (in_size /. in_time) (!in_size_sum /. !in_time_sum);
)
| SUB -> (fun () ->
Zmq.Socket.recv_all socket_in |> Zmq.Socket.send_all socket_out)
end
else
begin
match req_or_sub with
| REQ -> (fun () ->
Zmq.Socket.recv_all socket_in |> Zmq.Socket.send_all socket_out;
Zmq.Socket.recv_all socket_out |> Zmq.Socket.send_all socket_in )
| SUB -> (fun () ->
Zmq.Socket.recv_all socket_in |> Zmq.Socket.send_all socket_out)
end
in
*)
let action_in =
match req_or_sub with

View File

@ -1,13 +1,14 @@
#!/usr/bin/env python2
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from __future__ import print_function
import os
import sys
try:
QP_ROOT = os.environ['QP_ROOT']
except:
print "source quantum_package.rc"
print("source quantum_package.rc")
sys.exit(1)
else:
QP_EZFIO = os.environ["QP_EZFIO"]

View File

@ -1,11 +1,11 @@
#!/usr/bin/env python2
#!/usr/bin/env python3
import sys
with open(sys.argv[1],'r') as f:
raw_data = f.read()
print "set -x"
print("set -x")
output = []
inside = False
@ -25,9 +25,9 @@ for i in raw_data:
level -= 1
output.append(new_i)
print "".join(output).replace("@test ",
print("".join(output).replace("@test ",
"""[[ -z $BATS_TEST_NUMBER ]] && BATS_TEST_NUMBER=0 || ((++BATS_TEST_NUMBER)) ;
export BATS_TEST_DESCRIPTION=""").replace("skip","return")
export BATS_TEST_DESCRIPTION=""").replace("skip","return"))