This commit is contained in:
Pierre-Francois Loos 2020-10-13 13:44:24 +02:00
parent cd4f187c9b
commit a5bd9c218b
28 changed files with 323 additions and 374 deletions

BIN
GoDuck

Binary file not shown.

View File

@ -1,13 +1,13 @@
# RHF UHF MOM
T F F
# RHF UHF KS MOM
F T F F
# MP2* MP3 MP2-F12
F F F
# CCD CCSD CCSD(T)
T F F
F F F
# drCCD rCCD lCCD pCCD
F F F T
F F F F
# CIS* CIS(D) CID CISD
F F F F
T F F F
# RPA* RPAx* ppRPA
F F F
# G0F2 evGF2 G0F3 evGF3

View File

@ -1,8 +1,9 @@
#!/bin/bash
git clone --single-branch --branch master https://gitlab.com/libxc/libxc.git
cd libxc
autoreconf -i
###git clone --single-branch --branch master https://gitlab.com/libxc/libxc.git
tar -xzvf libxc-5.0.0.tar.gz
cd libxc-5.0.0
###autoreconf -i
./configure --prefix=$QUACK_ROOT
make
make check

119
scan_w.sh
View File

@ -1,119 +0,0 @@
#! /bin/bash
MOL=$1
BASIS=$2
w_start=0.00
w_end=1.05
dw=0.05
w1=0.00
XF=$3
CF=$4
# for H
#aw1="1.49852 7.79815 25.1445"
#aw2="0.424545 -0.0382349 -0.32472"
# for He
#aw1="0.429447 0.053506 -0.339391"
#aw2="0.254939 -0.0893396 0.00765453"
# for H2
aw1="0.445525 0.0901503 -0.286898"
aw2="0.191734 -0.0364788 -0.017035"
# for Li
#aw1="0.055105 -0.00943825 -0.0267771"
#aw2="0.0359827 0.0096623 -0.0173542"
# for Li+
#aw1="0.503566, 0.137076, -0.348529"
#aw2="0.0553828, 0.00830375, -0.0234602"
# for B
#aw1="0.052676 -0.00624118 -0.000368825"
#aw2="0.0385558 -0.0015764 -0.000894297"
# for O
#aw1="-0.0187067 -0.0141017 -0.0100849"
#aw2="0.00544868 -0.0000118236 -0.000163245"
# for Al
#aw1="-0.00201219 -0.00371002 -0.00212719"
#aw2="-0.00117715 0.00188738 -0.000414761"
# for Be
#aw1="0.0663282, -0.0117682, -0.0335909"
#aw2="0.0479262, 0.00966351, -0.0208712"
DATA=${MOL}_${BASIS}_${XF}_${CF}_${w2}.dat
rm $DATA
touch $DATA
for w2 in $(seq $w_start $dw $w_end)
do
## w2=${w1}
echo "# Restricted or unrestricted KS calculation" > input/dft
echo " eDFT-UKS" >> input/dft
echo "# exchange rung:" >> input/dft
echo "# Hartree = 0" >> input/dft
echo "# LDA = 1: RS51,RMFL20" >> input/dft
echo "# GGA = 2: RB88" >> input/dft
echo "# Hybrid = 4" >> input/dft
echo "# Hartree-Fock = 666" >> input/dft
echo " 1 $XF " >> input/dft
echo "# correlation rung: " >> input/dft
echo "# Hartree = 0" >> input/dft
echo "# LDA = 1: RVWN5,RMFL20" >> input/dft
echo "# GGA = 2: " >> input/dft
echo "# Hybrid = 4: " >> input/dft
echo "# Hartree-Fock = 666" >> input/dft
echo " 0 $CF " >> input/dft
echo "# quadrature grid SG-n" >> input/dft
echo " 1" >> input/dft
echo "# Number of states in ensemble (nEns)" >> input/dft
echo " 3" >> input/dft
echo "# occupation numbers of orbitals nO and nO+1" >> input/dft
echo " 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 " >> input/dft
echo " 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 " >> input/dft
echo " " >> input/dft
echo " 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 " >> input/dft
echo " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 " >> input/dft
echo " " >> input/dft
echo " 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 " >> input/dft
echo " 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 " >> input/dft
echo "# Ensemble weights: wEns(1),...,wEns(nEns-1)" >> input/dft
echo " ${w1} ${w2} " >> input/dft
echo "# Ncentered ? 0 for NO " >> input/dft
echo " 0 " >> input/dft
echo "# Parameters for CC weight-dependent exchange functional" >> input/dft
echo ${aw1} >> input/dft
echo ${aw2} >> input/dft
echo "# choice of UCC exchange coefficient : 1 for Cx1, 2 for Cx2, 3 for Cx1*Cx2" >> input/dft
echo "2" >> input/dft
echo "# GOK-DFT: maxSCF thresh DIIS n_diis guess_type ortho_type" >> input/dft
echo " 1000 0.00001 T 5 1 1" >> input/dft
OUTPUT=${MOL}_${BASIS}_${XF}_${CF}_${w2}.out
./GoXC $MOL $BASIS > ${OUTPUT}
Ew=`grep "Ensemble energy:" ${OUTPUT} | cut -d":" -f 2 | sed 's/au//'`
E0=`grep "Individual energy state 1:" ${OUTPUT} | cut -d":" -f 2 | sed 's/au//'`
E1=`grep "Individual energy state 2:" ${OUTPUT} | cut -d":" -f 2 | sed 's/au//'`
E2=`grep "Individual energy state 3:" ${OUTPUT} | cut -d":" -f 2 | sed 's/au//'`
IP=`grep "Ionization Potential" ${OUTPUT} | grep " au" | tail -1 | cut -d":" -f 2 | sed 's/au//'`
EA=`grep "Electronic Affinity" ${OUTPUT} | grep " au" | tail -1 | cut -d":" -f 2 | sed 's/au//'`
FG=`grep "Fundamental Gap" ${OUTPUT} | grep " au" | tail -1 | cut -d":" -f 2 | sed 's/au//'`
Ex=`grep "Exchange energy:" ${OUTPUT} | cut -d":" -f 2 | sed 's/au//'`
HOMOa=`grep "HOMO a energy:" ${OUTPUT} | cut -d":" -f 2 | sed 's/eV//'`
LUMOa=`grep "LUMO a energy:" ${OUTPUT} | cut -d":" -f 2 | sed 's/eV//'`
HOMOb=`grep "HOMO a energy:" ${OUTPUT} | cut -d":" -f 2 | sed 's/eV//'`
LUMOb=`grep "LUMO b energy:" ${OUTPUT} | cut -d":" -f 2 | sed 's/eV//'`
echo $w1 $w2 $Ew $E0 $E1 $E2 $IP $EA $FG $Ex $HOMOa $LUMOa $HOMOb $LUMOb
echo $w1 $w2 $Ew $E0 $E1 $E2 $IP $EA $FG $Ex $HOMOa $LUMOa $HOMOb $LUMOb >> ${DATA}
done

View File

@ -1,3 +1,3 @@
QUACK_ROOT=/Users/loos/Dropbox/quack
TARGET=ADC.a
include $(QUACK_ROOT)/src/Makefile.include
default:
ninja
make -C ..

View File

@ -1,3 +1,3 @@
QUACK_ROOT=/Users/loos/Dropbox/quack
TARGET=AOtoMO.a
include $(QUACK_ROOT)/src/Makefile.include
default:
ninja
make -C ..

View File

@ -1,3 +1,3 @@
QUACK_ROOT=/Users/loos/Dropbox/quack
TARGET=BasCor.a
include $(QUACK_ROOT)/src/Makefile.include
default:
ninja
make -C ..

View File

@ -1,3 +1,3 @@
QUACK_ROOT=/Users/loos/Dropbox/quack
TARGET=CC.a
include $(QUACK_ROOT)/src/Makefile.include
default:
ninja
make -C ..

View File

@ -1,3 +1,3 @@
QUACK_ROOT=/Users/loos/Dropbox/quack
TARGET=CI.a
include $(QUACK_ROOT)/src/Makefile.include
default:
ninja
make -C ..

View File

@ -1,3 +1,3 @@
QUACK_ROOT=/Users/loos/Dropbox/quack
TARGET=HF.a
include $(QUACK_ROOT)/src/Makefile.include
default:
ninja
make -C ..

View File

@ -1,88 +0,0 @@
subroutine linear_response_ph(ispin,dRPA,TDA,BSE,nBas,nC,nO,nV,nR,nS,e,ERI,rho,Ec_phRPA,Omega,XpY)
! Compute the p-h channel of the linear response
implicit none
include 'parameters.h'
! Input variables
logical,intent(in) :: dRPA,TDA,BSE
integer,intent(in) :: ispin,nBas,nC,nO,nV,nR,nS
double precision,intent(in) :: e(nBas),ERI(nBas,nBas,nBas,nBas),rho(nBas,nBas,nS)
! Local variables
double precision,external :: trace_matrix
double precision,allocatable :: A(:,:),B(:,:),M(:,:),w(:)
! Output variables
double precision,intent(out) :: Ec_phRPA
double precision,intent(out) :: Omega(nS),XpY(nS,nS)
! Memory allocation
allocate(A(nS,nS),B(nS,nS),M(2*nS,2*nS),w(2*nS))
! Build A and B matrices
call linear_response_A_matrix(ispin,dRPA,nBas,nC,nO,nV,nR,nS,e,ERI,A)
if(BSE) call Bethe_Salpeter_A_matrix(nBas,nC,nO,nV,nR,nS,ERI,Omega,rho,A)
! Tamm-Dancoff approximation
B(:,:) = 0d0
if(.not. TDA) then
call linear_response_B_matrix(ispin,dRPA,nBas,nC,nO,nV,nR,nS,ERI,B)
if(BSE) call Bethe_Salpeter_B_matrix(nBas,nC,nO,nV,nR,nS,ERI,Omega,rho,B)
endif
!------------------------------------------------------------------------
! Solve the p-h eigenproblem
!------------------------------------------------------------------------
!
! | +A +B | | X Y | | w 0 | | X Y |
! | | | | = | | | |
! | -B -A | | Y X | | 0 -w | | Y X |
!
! Diagonal blocks
M(1:nS,1:nS) = +A(1:nS,1:nS)
M(nS+1:2*nS,nS+1:2*nS) = -A(1:nS,1:nS)
! Off-diagonal blocks
M(1:nS,nS+1:2*nS) = -B(1:nS,1:nS)
M(nS+1:2*nS,1:nS) = +B(1:nS,1:nS)
! Diagonalize the p-h matrix
call diagonalize_matrix(2*nS,M(:,:),w(:))
Omega(1:nS) = w(nS+1:2*nS)
! Build X+Y
XpY(1:nS,1:nS) = M(nS+1:2*nS,1:nS) + M(nS+1:2*nS,nS+1:2*nS)
call DA(nS,1d0/sqrt(Omega),XpY)
! print*,'X+Y'
! call matout(nS,nS,XpY)
! print*,'RPA excitations'
call matout(2*nS,1,w(:))
! Compute the RPA correlation energy
Ec_phRPA = 0.5d0*(sum(Omega) - trace_matrix(nS,A))
print*,'Ec_phRPA = ',Ec_phRPA
end subroutine linear_response_ph

View File

@ -1,3 +1,3 @@
QUACK_ROOT=/Users/loos/Dropbox/quack
TARGET=MBPT.a
include $(QUACK_ROOT)/src/Makefile.include
default:
ninja
make -C ..

View File

@ -1,3 +1,3 @@
QUACK_ROOT=/Users/loos/Dropbox/quack
TARGET=MC.a
include $(QUACK_ROOT)/src/Makefile.include
default:
ninja
make -C ..

View File

@ -1,3 +1,3 @@
QUACK_ROOT=/Users/loos/Dropbox/quack
TARGET=MP.a
include $(QUACK_ROOT)/src/Makefile.include
default:
ninja
make -C ..

View File

@ -1,62 +1,14 @@
.SECONDARY:
QUACK_ROOT=$(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))/..))
export QUACK_ROOT
SDIR=$(QUACK_ROOT)/src
ALL_DIRS=$(patsubst %/,%,$(wildcard */))
default: build.ninja
python3 make_ninja.py
ninja
# Rules for Modules
###################
MOD_DIRS=libnumgrid
# Rules for Libraries
#####################
LDIR =$(QUACK_ROOT)/lib
LIB_DIRS=$(filter-out $(MAIN_DIRS), $(ALL_DIRS))
FORCE:
$(SDIR)/%/Makefile: FORCE
@(echo QUACK_ROOT=$(QUACK_ROOT) > $@)
@(echo TARGET=$*.a >> $@)
@(echo 'include $$(QUACK_ROOT)/src/Makefile.include' >> $@)
$(LDIR)/%.a: FORCE $(SDIR)/%/Makefile $(MOD_DIRS)
$(MAKE) -C $(SDIR)/$* lib
# Rules for executables
#######################
MAIN_DIRS=QuAcK eDFT
BDIR=$(QUACK_ROOT)/bin
ALL_EXEC=$(patsubst %, $(BDIR)/%, $(MAIN_DIRS) )
$(BDIR)/%: $(patsubst %,$(LDIR)/%.a,$(LIB_DIRS)) $(SDIR)/%/Makefile
$(MAKE) -C $* $@
# Rules for both
################
default: $(ALL_EXEC) $(wildcard $(SDIR)/*/Makefile)
debug:
DEBUG=1 $(MAKE) default
.DEFAULT_GOAL := default
.PHONY: default debug
.PRECIOUS: $(wildcard $(LDIR)/*.a) $(wildcard $(SDIR)/*/Makefile)
.PRECIOUS: /Users/loos/Dropbox/quack/lib/CI.a /Users/loos/Dropbox/quack/lib/CC.a /Users/loos/Dropbox/quack/lib/ADC.a /Users/loos/Dropbox/quack/lib/MP.a /Users/loos/Dropbox/quack/lib/libnumgrid.a /Users/loos/Dropbox/quack/lib/utils.a /Users/loos/Dropbox/quack/lib/HF.a /Users/loos/Dropbox/quack/lib/LR.a /Users/loos/Dropbox/quack/lib/AOtoMO.a /Users/loos/Dropbox/quack/lib/BasCor.a /Users/loos/Dropbox/quack/lib/RPA.a /Users/loos/Dropbox/quack/lib/MC.a /Users/loos/Dropbox/quack/lib/MBPT.a
clean:
rm -f -- $(patsubst %/,$(LDIR)/%.a,$(wildcard */)) ; \
rm -f -- $(ALL_EXEC) ; \
for i in $(MAIN_DIRS) $(LIB_DIRS) ; do rm -f -- $$i/obj/* ; done
clean: build.ninja
python3 make_ninja.py
ninja -t clean
for i in */ ; do ninja -t clean ; done

View File

@ -1,12 +0,0 @@
IDIR =$(QUACK_ROOT)/include
FC = gfortran -I$(IDIR) -J$(IDIR)
#FC = ifort -I$(IDIR) -module $(IDIR)
AR = libtool
ifeq ($(DEBUG),1)
FFLAGS = -Wall -g -msse4.2 -fcheck=all -Waliasing -Wampersand -Wconversion -Wsurprising -Wintrinsics-std -Wno-tabs -Wintrinsic-shadow -Wline-truncation -Wreal-q-constant
else
FFLAGS = -Wall -Wno-unused -Wno-unused-dummy-argument -O3
endif

View File

@ -1,44 +0,0 @@
BDIR =$(QUACK_ROOT)/bin
LDIR =$(QUACK_ROOT)/lib
IDIR =$(QUACK_ROOT)/include
ODIR = obj
SDIR =.
include $(QUACK_ROOT)/src/Makefile.common
LIBS = $(filter-out $(LDIR)/$(TARGET), $(wildcard $(LDIR)/*.a))
LIBS += -lblas -llapack -lc++
SRCF90 = $(wildcard *.f90)
SRC = $(wildcard *.f)
OBJ = $(patsubst %.f90,$(ODIR)/%.o,$(SRCF90)) $(patsubst %.f,$(ODIR)/%.o,$(SRC))
FORCE:
$(ODIR)/%.o: %.f90
$(FC) -c -o $@ $< $(FFLAGS)
$(ODIR)/%.o: %.f
$(FC) -c -o $@ $< $(FFLAGS)
$(LDIR)/$(TARGET): $(patsubst %,$(LDIR)/%,$(DEPEND)) $(OBJ)
$(AR) -static -o $@ $^
if [[ $(echo *.mod).x != ".x" ]] ; then mv -f *.mod $(IDIR) ; fi
debug:
DEBUG=1 $(MAKE) $(LDIR)/$(TARGET)
clean:
rm -f $(ODIR)/*.o $(LDIR)/$(TARGET)
$(BDIR)/%: $(OBJ) FORCE
$(FC) -o $@ $(FFLAGS) $(LIBS) $(OBJ)
default:
$(MAKE) -C $(QUACK_ROOT)/src
lib: $(LDIR)/$(TARGET)
.DEFAULT_GOAL := default
.PHONY: lib default

View File

@ -1,3 +0,0 @@
QUACK_ROOT=/Users/loos/Dropbox/quack
TARGET=QuAcK.a
include $(QUACK_ROOT)/src/Makefile.include

View File

@ -6,6 +6,7 @@ program QuAcK
logical :: doSph
logical :: unrestricted = .false.
logical :: doRHF,doUHF,doMOM
logical :: doKS
logical :: doMP2,doMP3,doMP2F12
logical :: doCCD,doCCSD,doCCSDT
logical :: do_drCCD,do_rCCD,do_lCCD,do_pCCD
@ -75,6 +76,7 @@ program QuAcK
double precision :: start_QuAcK ,end_QuAcK ,t_QuAcK
double precision :: start_int ,end_int ,t_int
double precision :: start_HF ,end_HF ,t_HF
double precision :: start_KS ,end_KS ,t_KS
double precision :: start_MOM ,end_MOM ,t_MOM
double precision :: start_AOtoMO ,end_AOtoMO ,t_AOtoMO
double precision :: start_CCD ,end_CCD ,t_CCD
@ -151,7 +153,7 @@ program QuAcK
! Which calculations do you want to do?
call read_methods(doRHF,doUHF,doMOM, &
call read_methods(doRHF,doUHF,doKS,doMOM, &
doMP2,doMP3,doMP2F12, &
doCCD,doCCSD,doCCSDT, &
do_drCCD,do_rCCD,do_lCCD,do_pCCD, &
@ -245,7 +247,6 @@ program QuAcK
else
! call system('./GoQCaml')
call read_integrals(nBas,S,T,V,Hc,ERI_AO)
call read_dipole_integrals(nBas,dipole_int)
@ -288,7 +289,7 @@ program QuAcK
end if
!------------------------------------------------------------------------
! Compute RHF energy
! Compute UHF energy
!------------------------------------------------------------------------
if(doUHF) then
@ -307,6 +308,23 @@ program QuAcK
end if
!------------------------------------------------------------------------
! Compute KS energy
!------------------------------------------------------------------------
if(doKS) then
call cpu_time(start_KS)
! call KS(maxSCF_HF,thresh_HF,n_diis_HF,guess_type,nNuc,ZNuc,rNuc,ENuc, &
! nBas,nO,S,T,V,Hc,ERI_AO,dipole_int,X,EUHF,eHF,cHF,PHF)
call cpu_time(end_KS)
t_KS = end_KS - start_KS
write(*,'(A65,1X,F9.3,A8)') 'Total CPU time for KS = ',t_KS,' seconds'
write(*,*)
end if
!------------------------------------------------------------------------
! Maximum overlap method
!------------------------------------------------------------------------

View File

@ -1,4 +1,4 @@
subroutine read_methods(doRHF,doUHF,doMOM, &
subroutine read_methods(doRHF,doUHF,doKS,doMOM, &
doMP2,doMP3,doMP2F12, &
doCCD,doCCSD,doCCSDT, &
do_drCCD,do_rCCD,do_lCCD,do_pCCD, &
@ -15,7 +15,7 @@ subroutine read_methods(doRHF,doUHF,doMOM, &
! Input variables
logical,intent(out) :: doRHF,doUHF,doMOM
logical,intent(out) :: doRHF,doUHF,doKS,doMOM
logical,intent(out) :: doMP2,doMP3,doMP2F12
logical,intent(out) :: doCCD,doCCSD,doCCSDT
logical,intent(out) :: do_drCCD,do_rCCD,do_lCCD,do_pCCD
@ -38,6 +38,7 @@ subroutine read_methods(doRHF,doUHF,doMOM, &
doRHF = .false.
doUHF = .false.
doKS = .false.
doMOM = .false.
doMP2 = .false.
@ -80,10 +81,11 @@ subroutine read_methods(doRHF,doUHF,doMOM, &
! Read mean-field methods
read(1,*)
read(1,*) answer1,answer2,answer3
read(1,*) answer1,answer2,answer3,answer4
if(answer1 == 'T') doRHF = .true.
if(answer2 == 'T') doUHF = .true.
if(answer3 == 'T') doMOM = .true.
if(answer3 == 'T') doKS = .true.
if(answer4 == 'T') doMOM = .true.
! Read MPn methods

View File

@ -1,3 +1,3 @@
QUACK_ROOT=/Users/loos/Dropbox/quack
TARGET=RPA.a
include $(QUACK_ROOT)/src/Makefile.include
default:
ninja
make -C ..

View File

@ -1,3 +0,0 @@
QUACK_ROOT=/Users/loos/Dropbox/quack
TARGET=eDFT.a
include $(QUACK_ROOT)/src/Makefile.include

View File

@ -2,6 +2,8 @@ program eDFT
! exchange-correlation density-functional theory calculations
use xc_f90_lib_m
implicit none
include 'parameters.h'
@ -63,6 +65,8 @@ program eDFT
double precision,allocatable :: occnum(:,:,:)
integer :: Cx_choice
integer :: i, vmajor, vminor, vmicro
! Hello World
write(*,*)
@ -71,6 +75,13 @@ program eDFT
write(*,*) '******************************************'
write(*,*)
! Libxc version
call xc_f90_version(vmajor, vminor, vmicro)
write(*,'("Libxc version: ",I1,".",I1,".",I1)') vmajor, vminor, vmicro
call xcinfo()
!------------------------------------------------------------------------
! Read input information
!------------------------------------------------------------------------

224
src/make_ninja.py Executable file
View File

@ -0,0 +1,224 @@
#!/usr/bin/env python3
import os
import sys
if "QUACK_ROOT" not in os.environ:
os.chdir("..")
print("")
print("Please set the QUACK_ROOT environment variable, for example:")
print("")
print("$ export QUACK_ROOT={0}".format(os.getcwd()))
print("")
sys.exit(1)
QUACK_ROOT=os.environ["QUACK_ROOT"]
compile_gfortran_mac = """
FC = gfortran
AR = libtool
FFLAGS = -I$IDIR -J$IDIR -Wall -Wno-unused -Wno-unused-dummy-argument -O3
CC = gcc
CXX = g++
LAPACK=-lblas -llapack
STDCXX=-lc++
"""
compile_gfortran_mac_debug = """
FC = gfortran -I$IDIR -J$IDIR
AR = libtool
FFLAGS = -I$IDIR -J$IDIR -Wall -g -msse4.2 -fcheck=all -Waliasing -Wampersand -Wconversion -Wsurprising -Wintrinsics-std -Wno-tabs -Wintrinsic-shadow -Wline-truncation -Wreal-q-constant
CC = gcc
CXX = g++
LAPACK=-lblas -llapack
STDCXX=-lc++
"""
# TODO Change compiler here
# --------------------------
compiler = compile_gfortran_mac
#compiler = compile_gfortran_mac_debug
header = """#
# This file was automatically generated. Do not modify this file.
# To change compiling options, make the modifications in
# {0}/src/make_ninja.py
#
QUACK_ROOT={0}
IDIR=$QUACK_ROOT/include
LDIR=$QUACK_ROOT/lib
BDIR=$QUACK_ROOT/bin
SDIR=$QUACK_ROOT/src
""".format(QUACK_ROOT)
rule_fortran = """
rule fc
command = $FC $FFLAGS -c $in -o $out && (mv -f *.mod $IDIR &> /dev/null || :)
"""
rule_build_lib = """
rule build_lib
command = $AR -static $in -o $out
description = Linking $out
"""
rule_build_exe = """
LIBS = $LDIR/libxcf90.a $LDIR/libxc.a $LDIR/libslatec.a $LDIR/libnumgrid.a $LAPACK $STDCXX
rule build_exe
command = $FC $in $LIBS -o $out
pool = console
description = Linking $out
rule build_lib
command = cd $dir ; ninja $out
pool = console
description = Compiling $out
"""
rule_slatec = """
rule make_slatec
command = cd $QUACK_ROOT/slatec/src ; make static ; cp static/libslatec.a $LDIR
pool = console
description = Building Slatec
build $LDIR/libslatec.a: make_slatec
"""
rule_git_clone = """
rule git_clone
command = cd $QUACK_ROOT ; git clone $url
pool = console
description = Cloning $in
"""
build_numgrid = """
rule make_numgrid
command = cd $QUACK_ROOT/utils ; LDIR="$LDIR" SDIR="$SDIR" CC="$CC" CXX="$CXX" FC="$FC" ./install_numgrid.sh
description = Building numgrid
pool = console
build $LDIR/libnumgrid.a: make_numgrid
"""
build_in_lib_dir = "\n".join([
header,
compiler,
rule_fortran,
rule_build_lib,
])
build_in_exe_dir = "\n".join([
header,
compiler,
rule_fortran,
rule_build_exe,
])
build_main = "\n".join([
header,
compiler,
rule_git_clone,
build_numgrid,
rule_slatec,
])
exe_dirs = [ "QuAcK", "eDFT" ]
lib_dirs = list(filter(lambda x: os.path.isdir(x) and \
x not in exe_dirs, os.listdir(".")))
def create_ninja_in_libdir(directory):
def write_rule(f, source_file, replace):
obj_file = os.path.join("obj", source_file.replace(replace, ".o"))
f.write("build {0}: fc {1}\n".format(obj_file,source_file))
return obj_file
with open(os.path.join(directory, "build.ninja"),"w") as f:
f.write(build_in_lib_dir)
objects = []
for filename in os.listdir(directory):
for suffix in [".f", ".f90"]:
if filename.endswith(suffix):
obj_file = write_rule(f, filename, suffix)
objects.append(obj_file)
objects = " ".join(objects)
f.write("build $LDIR/{0}.a: build_lib {1}\n".format(directory,objects))
f.write("default $LDIR/{0}.a\n".format(directory))
def create_ninja_in_exedir(directory):
def write_rule(f, source_file, replace):
obj_file = os.path.join("obj", source_file.replace(replace, ".o"))
f.write("build {0}: fc {1}\n".format(obj_file,source_file))
return obj_file
with open(os.path.join(directory, "build.ninja"),"w") as f:
f.write(build_in_exe_dir)
objects = []
for filename in os.listdir(directory):
for suffix in [".f", ".f90"]:
if filename.endswith(suffix):
obj_file = write_rule(f, filename, suffix)
objects.append(obj_file)
objects = " ".join(objects)
for libname in lib_dirs:
f.write("build $LDIR/{0}.a: build_lib\n dir = $SDIR/{0}\n".format(libname))
libs = " ".join([ "$LDIR/{0}.a".format(x) for x in lib_dirs])
f.write("build $BDIR/{0}: build_exe {1} {2}\n".format(directory,libs,objects))
f.write("default $BDIR/{0}\n".format(directory))
def create_main_ninja():
libs = " ".join([ "$LDIR/{0}.a".format(x) for x in lib_dirs])
with open("build.ninja","w") as f:
f.write(build_main)
f.write("""
rule build_exe
command = cd $SDIR/$dir ; ninja $out
pool = console
rule build_lib
command = cd $dir ; ninja $out
pool = console
description = Compiling $out
""")
for exe_dir in exe_dirs:
f.write("build $BDIR/{0}: build_exe {1} $LDIR/libnumgrid.a $LDIR/libslatec.a\n".format(exe_dir,libs))
f.write(" dir = {0} \n".format(exe_dir) )
for libname in lib_dirs:
f.write("build $LDIR/{0}.a: build_lib\n dir = $SDIR/{0}\n".format(libname))
f.write("build all: phony $BDIR/QuAcK $BDIR/eDFT\n")
f.write("default all\n")
def create_makefile(directory):
with open(os.path.join(directory, "Makefile"),"w") as f:
f.write("""default:
ninja
make -C ..
""")
def main():
for lib_dir in lib_dirs:
create_ninja_in_libdir(lib_dir)
create_makefile(lib_dir)
for exe_dir in exe_dirs:
create_ninja_in_exedir(exe_dir)
create_makefile(lib_dir)
create_main_ninja()
if __name__ == '__main__':
main()

View File

@ -1,3 +1,3 @@
QUACK_ROOT=/Users/loos/Dropbox/quack
TARGET=utils.a
include $(QUACK_ROOT)/src/Makefile.include
default:
ninja
make -C ..

10
utils/install_numgrid.sh Executable file
View File

@ -0,0 +1,10 @@
#!/bin/bash -x
git clone https://github.com/dftlibs/numgrid.git
cd numgrid
./setup --fc="$FC" --cc="$CC" --cxx="$CXX"
cd build
make
cp lib/libnumgrid.a $LDIR/
cp ..//numgrid/numgrid.f90 $SDIR/numgrid/