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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@
-Date
-Name
-changes
--------------
July 17, 2025
Name: Sayan Bhowmik
Changes: src/include/isddft.h, src/initialization.c, src/readfiles.c, src/relax.c,
tests/Al_pr_relax_comp, tests/Al_pr_relax_tens, tests/SPARC_testing_script.py,
tests/README.md, doc/.LaTeX/Introduction.tex, doc/.LaTeX/Optimization.tex,doc/Manual.pdf
1. Added target pressure for cell relaxation.

--------------
June 17, 2025
Name: Tian Tian
Expand Down
4 changes: 2 additions & 2 deletions doc/.LaTeX/Introduction.tex
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
\item \textbf{Tian Tian}: Socket communication layer, code testing, Python API
\item \textbf{Lucas R Timmerman\footnotemark[2]}: Socket communication layer, code testing, Python API
\end{itemize}
\end{itemize}
\end{itemize}
\footnotetext[1]{co-advised with Andrew J. Medford}
\footnotetext[2]{co-advised with Phanish Suryanarayana}
\end{frame}
Expand Down Expand Up @@ -378,7 +378,7 @@
\hyperlink{RELAX_METHOD}{\texttt{RELAX\_METHOD}} $\vert$
\hyperlink{RELAX_NITER}{\texttt{RELAX\_NITER}} $\vert$
\hyperlink{TOL_RELAX}{\texttt{TOL\_RELAX}} $\vert$
\hyperlink{TOL_RELAX_CELL}{\texttt{TOL\_RELAX\_CELL}} $\vert$
\hyperlink{TOL_RELAX_CELL}{\texttt{TOL\_RELAX\_CELL}} $\vert$ \hyperlink{RELAX_PRESSURE}{\texttt{RELAX\_PRESSURE}} $\vert$
\hyperlink{RELAX_MAXDILAT}{\texttt{RELAX\_MAXDILAT}} $\vert$
\hyperlink{NLCG_SIGMA}{\texttt{NLCG\_SIGMA}} $\vert$
\hyperlink{L_HISTORY}{\texttt{L\_HISTORY}} $\vert$
Expand Down
32 changes: 32 additions & 0 deletions doc/.LaTeX/Optimization.tex
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,38 @@
\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[allowframebreaks]{\texttt{RELAX\_PRESSURE}} \label{RELAX_PRESSURE}
\vspace*{-12pt}
\begin{columns}
\column{0.4\linewidth}
\begin{block}{Type}
Double
\end{block}

\begin{block}{Default}
0.0
\end{block}

\column{0.4\linewidth}
\begin{block}{Unit}
GPa
\end{block}

\begin{block}{Example}
\texttt{RELAX\_PRESSURE}: 4.53
\end{block}
\end{columns}

\begin{block}{Description}
Specifies the target outer pressure for cell volume relaxation - \hyperlink{RELAX_FLAG}{\texttt{RELAX\_FLAG}}: 2 or \hyperlink{RELAX_FLAG}{\texttt{RELAX\_FLAG}}: 3.
\end{block}

%\begin{block}{Remark}
%\end{block}

\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}[allowframebreaks]{\texttt{RELAX\_MAXDILAT}} \label{RELAX_MAXDILAT}
Expand Down
Binary file modified doc/Manual.pdf
Binary file not shown.
2 changes: 2 additions & 0 deletions src/include/isddft.h
Original file line number Diff line number Diff line change
Expand Up @@ -857,6 +857,7 @@ typedef struct _SPARC_OBJ{
double qmass; // mass parameter
double amu2au; // conversion factor for atomic mass unit -> atomic unit of mass
double fs2atu; // conversion factor for femto second -> atomic unit of time (Jiffy)
double relaxPrTarget; // Target pressure for cell relaxation in GPa
// NPT
int NPTscaleVecs[3]; // which lattice vector can be rescaled?
int NPTconstraintFlag; // confinement on side length of cell. none: no length confinement (default); 1: a:b keeps unchanged; 2: a:c keeps unchanged;
Expand Down Expand Up @@ -1349,6 +1350,7 @@ typedef struct _SPARC_INPUT_OBJ{
int L_history;
int L_autoscale;
int L_lineopt;
double relaxPrTarget; // Target pressure for cell relaxation in GPa

/* Stress options*/
int Calc_stress;
Expand Down
16 changes: 12 additions & 4 deletions src/initialization.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@
#define min(x,y) ((x)<(y)?(x):(y))
#define max(x,y) ((x)>(y)?(x):(y))

#define N_MEMBR 209
// #define N_MEMBR 208
#define N_MEMBR 210


/**
Expand Down Expand Up @@ -856,6 +855,7 @@ void set_defaults(SPARC_INPUT_OBJ *pSPARC_Input, SPARC_OBJ *pSPARC) {
/* Default cell relaxation parameters*/
pSPARC_Input->max_dilatation = 1.06; // maximum lattice dilatation
pSPARC_Input->TOL_RELAX_CELL = 1e-2; // in GPa (all periodic)
pSPARC_Input->relaxPrTarget = 0; // Default relaxation pressure in 0 GPa

/* Default band structure calculation parameters */
pSPARC_Input->BandStructFlag = 0;
Expand Down Expand Up @@ -1575,6 +1575,7 @@ void SPARC_copy_input(SPARC_OBJ *pSPARC, SPARC_INPUT_OBJ *pSPARC_Input) {
pSPARC->OFDFT_lambda = pSPARC_Input->OFDFT_lambda;
pSPARC->twist = pSPARC_Input->twist;
pSPARC->is_hubbard = pSPARC_Input->is_hubbard; // DFT+U
pSPARC->relaxPrTarget = pSPARC_Input->relaxPrTarget; // Target pressure for cell relaxation

// char type values
strncpy(pSPARC->MDMeth , pSPARC_Input->MDMeth,sizeof(pSPARC->MDMeth));
Expand Down Expand Up @@ -1704,7 +1705,7 @@ void SPARC_copy_input(SPARC_OBJ *pSPARC, SPARC_INPUT_OBJ *pSPARC_Input) {
if (pSPARC->BandStructFlag == 1) {
pSPARC->MAXIT_SCF = 1;
pSPARC->MINIT_SCF = 1;
if (pSPARC->is_hubbard) pSPARC->MAXIT_SCF = 50;
// if (pSPARC->is_hubbard) pSPARC->MAXIT_SCF = 50; // need to work on hubbard band
pSPARC->PrintElecDensFlag = 0;
pSPARC->PrintEigenFlag = 1;
}
Expand Down Expand Up @@ -3856,6 +3857,10 @@ void write_output_init(SPARC_OBJ *pSPARC) {
}
}

if (pSPARC->RelaxFlag > 1) {
fprintf(output_fp,"RELAX_PRESSURE: %.15g\n",pSPARC->relaxPrTarget);
}

fprintf(output_fp,"CALC_STRESS: %d\n",pSPARC->Calc_stress);
if(pSPARC->Calc_stress == 0)
fprintf(output_fp,"CALC_PRES: %d\n",pSPARC->Calc_pres);
Expand Down Expand Up @@ -4355,6 +4360,7 @@ void SPARC_Input_MPI_create(MPI_Datatype *pSPARC_INPUT_MPI) {
MPI_DOUBLE, MPI_DOUBLE, MPI_DOUBLE, MPI_DOUBLE, MPI_DOUBLE,
MPI_DOUBLE, MPI_DOUBLE, MPI_DOUBLE, MPI_DOUBLE, MPI_DOUBLE,
MPI_DOUBLE, MPI_DOUBLE, MPI_DOUBLE, MPI_DOUBLE, MPI_DOUBLE,
MPI_DOUBLE,
MPI_CHAR, MPI_CHAR, MPI_CHAR, MPI_CHAR, MPI_CHAR,
MPI_CHAR, MPI_CHAR, MPI_CHAR, MPI_CHAR, MPI_CHAR};
int blens[N_MEMBR] = {3, 3, 7, /* int array */
Expand Down Expand Up @@ -4397,7 +4403,7 @@ void SPARC_Input_MPI_create(MPI_Datatype *pSPARC_INPUT_MPI) {
1, 1, 1, 1, 1,
1, 1, 1, 1, 1,
1, 1, 1, 1, 1,
1, /* double */
1, 1, /* double */
32, 32, 32, L_STRING, L_STRING, /* char */
L_STRING, L_STRING, L_STRING, L_STRING, L_STRING};

Expand Down Expand Up @@ -4611,6 +4617,8 @@ void SPARC_Input_MPI_create(MPI_Datatype *pSPARC_INPUT_MPI) {
MPI_Get_address(&sparc_input_tmp.xi_3_SOAP, addr + i++);
MPI_Get_address(&sparc_input_tmp.F_tol_SOAP, addr + i++);
MPI_Get_address(&sparc_input_tmp.F_rel_scale, addr + i++);

MPI_Get_address(&sparc_input_tmp.relaxPrTarget, addr + i++);


// char type
Expand Down
3 changes: 3 additions & 0 deletions src/readfiles.c
Original file line number Diff line number Diff line change
Expand Up @@ -1014,6 +1014,9 @@ void read_input(SPARC_INPUT_OBJ *pSPARC_Input, SPARC_OBJ *pSPARC) {
fscanf(input_fp, "%*[^\n]\n");
} else if(strcmpi(str,"HUBBARD_FLAG:") == 0) {
fscanf(input_fp,"%d",&pSPARC_Input->is_hubbard);
} else if (strcmpi(str,"RELAX_PRESSURE:") == 0) {
fscanf(input_fp,"%lf",&pSPARC_Input->relaxPrTarget); // input in GPa
fscanf(input_fp, "%*[^\n]\n");
} else {
printf("\nCannot recognize input variable identifier: \"%s\"\n",str);
exit(EXIT_FAILURE);
Expand Down
7 changes: 5 additions & 2 deletions src/relax.c
Original file line number Diff line number Diff line change
Expand Up @@ -1071,8 +1071,11 @@ double volrelax_constraint(SPARC_OBJ *pSPARC, double vol)
// free memory
free(stress_lc);

// return max pressure stress
return max_P_stress;
// return max pressure stress - target relaxation pressure
#ifdef DEBUG
if (rank == 0) printf("\n\n CELL_RELAX residual = %6.6f\n\n",-max_P_stress - pSPARC->relaxPrTarget);
#endif
return (-max_P_stress - pSPARC->relaxPrTarget);
}


Expand Down
30 changes: 30 additions & 0 deletions tests/Al_pr_relax_comp/high_accuracy/Al_pr_relax_comp.inpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@

LATVEC_SCALE: 1 1 1
LATVEC:
7.628635126863900 0.000000000000000 0.000000000000000
0.000000000000000 7.628635126863900 0.000000000000000
0.000000000000000 0.000000000000000 7.628635126863900
BC: P P P


EXCHANGE_CORRELATION: GGA_PBE


MESH_SPACING: 0.3

KPOINT_GRID: 4 4 4

RELAX_FLAG: 2
RELAX_PRESSURE: 1.0517108455E+01
PRECOND_KERKER_THRESH: 0.0
MIXING_PARAMETER: 1.0
TOL_SCF: 1e-5

TOL_RELAX_CELL: 1e-4

CALC_STRESS: 1
PRINT_ATOMS: 1
PRINT_VELS: 0
PRINT_FORCES: 1
PRINT_EIGEN: 0
PRINT_DENSITY: 0
22 changes: 22 additions & 0 deletions tests/Al_pr_relax_comp/high_accuracy/Al_pr_relax_comp.ion
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#=========================
# format of ion file
#=========================
# ATOM_TYPE: <atom type name>
# N_TYPE_ATOM: <num of atoms of this type>
# COORD:
# <xcoord> <ycoord> <zcoord>
# ...
# RELAX:
# <xrelax> <yrelax> <zrelax>
# ...

ATOM_TYPE: Al # atom type
ATOMIC_MASS: 26.981539 # atomic mass (amu)
PSEUDO_POT: ../../../psps/13_Al_3_1.9_1.9_pbe_n_v1.0.psp8 # pseudopotential file
N_TYPE_ATOM: 4 # number of atoms of this type

COORD_FRAC: # fractional coordinates (in lattice vector basis)
0 0 0
0.500000000000000 0 0.500000000000000
0 0.500000000000000 0.500000000000000
0.500000000000000 0.500000000000000 0
77 changes: 77 additions & 0 deletions tests/Al_pr_relax_comp/high_accuracy/Al_pr_relax_comp.refgeopt
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
:RELAXSTEP: 1
:CELL: 7.1968255914E+00 7.1968255914E+00 7.1968255914E+00
:VOLUME: 3.7275453360E+02
:LATVEC:
7.6286351269E+00 0.0000000000E+00 0.0000000000E+00
0.0000000000E+00 7.6286351269E+00 0.0000000000E+00
0.0000000000E+00 0.0000000000E+00 7.6286351269E+00
:STRESS:
-2.1455556480E+01 -2.5012302310E-05 -2.0250002617E-05
-2.5012302310E-05 -2.1455590725E+01 7.7442436596E-06
-2.0250002617E-05 7.7442436596E-06 -2.1455551991E+01
:RELAXSTEP: 2
:CELL: 8.0863532345E+00 8.0863532345E+00 8.0863532345E+00
:VOLUME: 5.2875943009E+02
:LATVEC:
7.6286351269E+00 0.0000000000E+00 0.0000000000E+00
0.0000000000E+00 7.6286351269E+00 0.0000000000E+00
0.0000000000E+00 0.0000000000E+00 7.6286351269E+00
:STRESS:
9.1186946090E+00 -1.8705453624E-05 -1.4033139065E-05
-1.8705453624E-05 9.1186987621E+00 -3.2639891749E-05
-1.4033139065E-05 -3.2639891749E-05 9.1186981710E+00
:RELAXSTEP: 3
:CELL: 7.5394538008E+00 7.5394538008E+00 7.5394538008E+00
:VOLUME: 4.2856791386E+02
:LATVEC:
7.6286351269E+00 0.0000000000E+00 0.0000000000E+00
0.0000000000E+00 7.6286351269E+00 0.0000000000E+00
0.0000000000E+00 0.0000000000E+00 7.6286351269E+00
:STRESS:
-3.3977303781E+00 5.3945778297E-06 3.2084911502E-06
5.3945778297E-06 -3.3977299811E+00 7.2015337552E-06
3.2084911502E-06 7.2015337552E-06 -3.3977280236E+00
:RELAXSTEP: 4
:CELL: 7.4081432839E+00 7.4081432839E+00 7.4081432839E+00
:VOLUME: 4.0656325138E+02
:LATVEC:
7.6286351269E+00 0.0000000000E+00 0.0000000000E+00
0.0000000000E+00 7.6286351269E+00 0.0000000000E+00
0.0000000000E+00 0.0000000000E+00 7.6286351269E+00
:STRESS:
-9.1044396494E+00 8.1259479995E-06 4.4663897619E-06
8.1259479995E-06 -9.1044381201E+00 1.0004538242E-05
4.4663897619E-06 1.0004538242E-05 -9.1044348809E+00
:RELAXSTEP: 5
:CELL: 7.3787258213E+00 7.3787258213E+00 7.3787258213E+00
:VOLUME: 4.0173911581E+02
:LATVEC:
7.6286351269E+00 0.0000000000E+00 0.0000000000E+00
0.0000000000E+00 7.6286351269E+00 0.0000000000E+00
0.0000000000E+00 0.0000000000E+00 7.6286351269E+00
:STRESS:
-1.0581149639E+01 7.8938299860E-06 4.7159635730E-06
7.8938299860E-06 -1.0581146660E+01 1.0579580687E-05
4.7159635730E-06 1.0579580687E-05 -1.0581144395E+01
:RELAXSTEP: 6
:CELL: 7.3800063989E+00 7.3800063989E+00 7.3800063989E+00
:VOLUME: 4.0194831753E+02
:LATVEC:
7.6286351269E+00 0.0000000000E+00 0.0000000000E+00
0.0000000000E+00 7.6286351269E+00 0.0000000000E+00
0.0000000000E+00 0.0000000000E+00 7.6286351269E+00
:STRESS:
-1.0515280592E+01 -8.8112912882E-07 -4.7978309086E-07
-8.8112912882E-07 -1.0515280628E+01 -1.0793483512E-06
-4.7978309086E-07 -1.0793483512E-06 -1.0515281000E+01
:RELAXSTEP: 7
:CELL: 7.3799708702E+00 7.3799708702E+00 7.3799708702E+00
:VOLUME: 4.0194251241E+02
:LATVEC:
7.6286351269E+00 0.0000000000E+00 0.0000000000E+00
0.0000000000E+00 7.6286351269E+00 0.0000000000E+00
0.0000000000E+00 0.0000000000E+00 7.6286351269E+00
:STRESS:
-1.0517100151E+01 5.5404930056E-08 2.0096430902E-08
5.5404930056E-08 -1.0517100160E+01 6.3923716335E-08
2.0096430902E-08 6.3923716335E-08 -1.0517100130E+01
Loading