Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Orbital projection tests #285

Merged
merged 31 commits into from
Nov 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
9080ac2
Reenable testShortSighted test (#248)
jeanlucf22 Jun 4, 2024
f13236f
Make new driver to check input (#247)
jeanlucf22 Jun 4, 2024
bad80d1
Add possible periodic dimensions to xyz2in.py (#249)
jeanlucf22 Jun 4, 2024
7aac379
Remove unused/untested option extrapolateH (#250)
jeanlucf22 Jun 4, 2024
bffc514
Exit with failure if density off by more than 2% (#251)
jeanlucf22 Jun 6, 2024
de1be3b
Example driver (#252)
jeanlucf22 Jun 6, 2024
13b8642
loadOrbitalsFromRestartFile -> loadRestartFile (#253)
dreamer2368 Jun 14, 2024
3eaf5a6
Add SG15 PBE potential for N (#258)
jeanlucf22 Jul 20, 2024
bc897c6
Update 2-pyridone example (#259)
jeanlucf22 Jul 22, 2024
3c11121
Adjust verbosity in some functions (#260)
jeanlucf22 Jul 29, 2024
35ba70f
Add new example: pinned H2O (#261)
jeanlucf22 Jul 29, 2024
bde8506
Print out eigenvalues out of MVP solver (#262)
jeanlucf22 Jul 30, 2024
4bbb64e
Add Li2 example with local GTH potential (#263)
jeanlucf22 Jul 31, 2024
0ead573
Fix LBFGS termination when converged (#264)
jeanlucf22 Jul 31, 2024
b7e75a2
Remove unused code to extrapolate rho (#265)
jeanlucf22 Jul 31, 2024
7bcd787
Fix and test EnergyAndForces interface (#266)
jeanlucf22 Aug 1, 2024
e0ad1a9
Add new functionality to compute energy and forces (#267)
jeanlucf22 Aug 8, 2024
8f03cb6
Add functionality to compute energy and forces (#270)
jeanlucf22 Aug 12, 2024
b62a593
Add ONCV for Sulfur + example (#275)
jeanlucf22 Sep 19, 2024
6a8a1d1
Merge branch 'release' into merge_release
siuwuncheung Sep 22, 2024
da33f94
Fix CMakeList
siuwuncheung Sep 22, 2024
f1d42a3
Fix test
siuwuncheung Sep 22, 2024
f0e2d22
Bypass build error
siuwuncheung Sep 23, 2024
a03c891
Fix merge mistake
siuwuncheung Sep 23, 2024
a747833
Add verification of orbital projection
siuwuncheung Oct 12, 2024
23db1ee
Make user defined options
siuwuncheung Oct 16, 2024
a27efba
Add scripts
siuwuncheung Oct 16, 2024
f0319f5
Merge branch 'ROMFPMD' into test_ROM_force
siuwuncheung Oct 18, 2024
bc5992d
Add get_result.sh
siuwuncheung Oct 31, 2024
83d8960
Merge branch 'test_ROM_force' of https://github.com/LLNL/mgmol into t…
siuwuncheung Oct 31, 2024
da6e19a
Add visualization scripts
siuwuncheung Oct 31, 2024
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
27 changes: 27 additions & 0 deletions examples/PinnedH2O/get_result.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
filename="offline_PinnedH2O.out" # FOM
#filename="rom39_PinnedH2O.out" # compare MD
#filename="39_force_PinnedH2O.out" # compare force

# Extracting H1, H2, F1, F2 from MGmgol output log
# if FOM, these files contain the FOM results
# if compare MD, these files contain the results with projected orbitals
awk '/H1 / {print $3, $4, $5}' $filename > H1_$filename
awk '/H2 / {print $3, $4, $5}' $filename > H2_$filename
awk '/F1 / {print $6, $7, $8}' $filename > F1_$filename
awk '/F2 / {print $6, $7, $8}' $filename > F2_$filename

# if compare force, files with "_fom" contain the FOM results
# files with "_rom" contain the results with projected orbitals
if [[ "$filename" == *"force_"* ]]; then
sed -n '1~2p' H1_$filename > H1_rom$filename
sed -n '1~2p' H2_$filename > H2_rom$filename
sed -n '1~2p' F1_$filename > F1_rom$filename
sed -n '1~2p' F2_$filename > F2_rom$filename

sed -n '2~2p' H1_$filename > H1_fom$filename
sed -n '2~2p' H2_$filename > H2_fom$filename
sed -n '2~2p' F1_$filename > F1_fom$filename
sed -n '2~2p' F2_$filename > F2_fom$filename
fi

rm -rf snapshot0_*
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/tcsh
#SBATCH -N 2
#SBATCH -t 0:10:00
#SBATCH -p pdebug
#SBATCH -p pbatch

date

Expand All @@ -10,23 +10,23 @@ setenv OMP_NUM_THREADS 1

set ncpus = 64

set maindir = /p/lustre2/cheung26/mgmol-20240815
set maindir = /p/lustre2/cheung26/mgmol-20241012

setenv LD_LIBRARY_PATH ${maindir}/build_quartz/libROM/build/lib:$LD_LIBRARY_PATH

set exe = ${maindir}/build_quartz/libROM/build/examples/misc/combine_samples

set snapshot_files = ""
set increment_md_steps = 1
set num_md_steps = 500
set num_md_steps = 50

foreach k (`seq $increment_md_steps $increment_md_steps $num_md_steps`)
set snapshot_files = "$snapshot_files MD_mdstep${k}_snapshot"
end
echo "Snapshot files: $snapshot_files"

set basis_file = "PinnedH2O_orbitals_basis"
set basis_file = "PinnedH2O_orbitals_basis_${increment_md_steps}_${num_md_steps}"

srun -n $ncpus $exe -f $basis_file $snapshot_files > basis_${increment_md_steps}_${num_md_steps}_Pinned_H2O.out
srun -n $ncpus $exe -f $basis_file $snapshot_files > basis_${increment_md_steps}_${num_md_steps}_PinnedH2O.out

date
8 changes: 4 additions & 4 deletions examples/PinnedH2O/job.rom → examples/PinnedH2O/job.offline
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ setenv OMP_NUM_THREADS 1

set ncpus = 64

set maindir = /p/lustre2/cheung26/mgmol-20240815
set maindir = /p/lustre2/cheung26/mgmol-20241012

setenv LD_LIBRARY_PATH ${maindir}/build_quartz/libROM/build/lib:$LD_LIBRARY_PATH

Expand All @@ -20,8 +20,8 @@ cp $maindir/install_quartz/bin/$exe .

set datadir = $maindir/examples/PinnedH2O

set cfg_rom = mgmol_rom.cfg
#cp $datadir/$cfg_rom .
set cfg_offline = mgmol_offline.cfg
cp $datadir/$cfg_offline .

cp $datadir/coords.in .

Expand All @@ -30,6 +30,6 @@ ln -s -f $maindir/potentials/pseudo.H_ONCV_PBE_SG15 .

source $maindir/scripts/modules.quartz

srun -n $ncpus $exe -c $cfg_rom -i coords.in > rom_PinnedH2O.out
srun -n $ncpus $exe -c $cfg_offline -i coords.in > offline_PinnedH2O.out

date
39 changes: 39 additions & 0 deletions examples/PinnedH2O/job.rom_1_50
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/bin/tcsh
#SBATCH -N 2
#SBATCH -t 1:00:00
#SBATCH -p pbatch

date

setenv OMP_NUM_THREADS 1
#setenv KMP_DETERMINISTIC_REDUCTION 1

set ncpus = 64

set maindir = /p/lustre2/cheung26/mgmol-20241012

setenv LD_LIBRARY_PATH ${maindir}/build_quartz/libROM/build/lib:$LD_LIBRARY_PATH

set exe = mgmol-opt

cp $maindir/install_quartz/bin/$exe .

set datadir = $maindir/examples/PinnedH2O

set increment_md_steps = 1
set num_md_steps = 50
set basis_file = PinnedH2O_orbitals_basis_${increment_md_steps}_${num_md_steps}

set cfg_rom = mgmol_rom_${increment_md_steps}_${num_md_steps}.cfg
cp $datadir/$cfg_rom .

cp $datadir/coords.in .

ln -s -f $maindir/potentials/pseudo.O_ONCV_PBE_SG15 .
ln -s -f $maindir/potentials/pseudo.H_ONCV_PBE_SG15 .

source $maindir/scripts/modules.quartz

srun -n $ncpus $exe -c $cfg_rom -i coords.in > rom_${increment_md_steps}_${num_md_steps}_PinnedH2O.out

date
File renamed without changes.
40 changes: 40 additions & 0 deletions examples/PinnedH2O/mgmol_rom_1_50.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
verbosity=1
xcFunctional=PBE
FDtype=Mehrstellen
[Mesh]
nx=64
ny=64
nz=64
[Domain]
ox=-6.
oy=-6.
oz=-6.
lx=12.
ly=12.
lz=12.
[Potentials]
pseudopotential=pseudo.O_ONCV_PBE_SG15
pseudopotential=pseudo.H_ONCV_PBE_SG15
[Run]
type=MD
[MD]
num_steps=500
dt=40.
thermostat=ON
[Thermostat]
type=Berendsen
temperature=1000.
relax_time=800.
[Quench]
max_steps=100
atol=1.e-8
[Orbitals]
initial_type=Random
initial_width=2.
[Restart]
output_level=4
[ROM.offline]
basis_file=PinnedH2O_orbitals_basis_1_50
[ROM.basis]
compare_md=false
number_of_orbital_basis=39
84 changes: 84 additions & 0 deletions examples/PinnedH2O/plot_PinnedH2O_force.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
clc; clear all; close all;

%%
plot_fom = 0;
plot_rom = 0;
rdim = 77;

%%
load F_fom.mat
fprintf(1, 'Force statistics using FOM orbitals\n');
fprintf(1, 'Mean of force on H1: %6.4e, %6.4e, %6.4e\n', mean(F1_fom));
fprintf(1, 'Variance of force on H1: %6.4e, %6.4e, %6.4e\n', var(F1_fom));
fprintf(1, 'Mean of force on H2: %6.4e, %6.4e, %6.4e\n', mean(F2_fom));
fprintf(1, 'Variance of force on H2: %6.4e, %6.4e, %6.4e\n', var(F2_fom));

if plot_fom
plotForce(F1_fom, 'F_H1_fom');
plotForce(F2_fom, 'F_H2_fom');
plotForceHistograms(F1_fom, 'H1_fom');
plotForceHistograms(F2_fom, 'H2_fom');
end

%%
load(['F_rom' int2str(rdim) '.mat'])
fprintf(1, 'Force statistics using projected orbitals\n');
fprintf(1, 'Mean of force on H1: %6.4e, %6.4e, %6.4e\n', mean(F1_rom));
fprintf(1, 'Variance of force on H1: %6.4e, %6.4e, %6.4e\n', var(F1_rom));
%H1_correlation = sum(F1_fom(:) .* F1_rom(:)) / (norm(F1_fom(:)) * norm(F1_rom(:)))
fprintf(1, 'Mean of force on H2: %6.4e, %6.4e, %6.4e\n', mean(F2_rom));
fprintf(1, 'Variance of force on H2: %6.4e, %6.4e, %6.4e\n', var(F2_rom));
%H2_correlation = sum(F2_fom(:) .* F2_rom(:)) / (norm(F2_fom(:)) * norm(F2_rom(:)))

if plot_rom
plotForce(F1_rom, ['F_H1_rom' int2str(rdim)]);
plotForce(F2_rom, ['F_H2_rom' int2str(rdim)]);
plotForceHistograms(F1_rom, ['H1_rom' int2str(rdim)]);
plotForceHistograms(F2_rom, ['H2_rom' int2str(rdim)]);
plotForceHistogram(abs(F1_fom - F1_rom), ['H1_rom' int2str(rdim)], 'Fdiff');
plotForceHistogram(abs(F2_fom - F2_rom), ['H2_rom' int2str(rdim)], 'Fdiff');
end

%%
function plotForce(F, suffix)
figure;
imagesc(F');
axis tight;
axis equal;
colorbar;
saveas(gcf, suffix, 'jpg');
end

function plotForceHistogram(F, suffix, var)
figure;
if strcmp(var,'Fx')
X = F(:,1);
var_name = 'x-directional Force';
elseif strcmp(var,'Fy')
X = F(:,2);
var_name = 'y-directional Force';
elseif strcmp(var,'Fz')
X = F(:,3);
var_name = 'z-directional Force';
elseif strcmp(var,'Fmag')
X = sqrt(sum(F.^2, 2));
var_name = 'Force Magitude';
elseif strcmp(var,'Fdiff')
X = sqrt(sum(F.^2, 2));
var_name = 'Magitude of Difference in Force';
else
error('Invalid type');
end
histogram(X, 20);
xlabel(var_name);
ylabel('Frequency');
title(['Histogram of ' var_name]);
saveas(gcf, [var '_' suffix], 'jpg');
end

function plotForceHistograms(F, suffix)
plotForceHistogram(F, suffix, 'Fx');
plotForceHistogram(F, suffix, 'Fy');
plotForceHistogram(F, suffix, 'Fz');
plotForceHistogram(F, suffix, 'Fmag');
end
59 changes: 59 additions & 0 deletions examples/PinnedH2O/plot_PinnedH2O_md.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
clc; clear all; close all;

%%
plot_fom = 0;
rdims = [77, 39];

%%
load md_fom.mat
if plot_fom
plotAngleHistogram(H1_fom, H2_fom, 'fom');
end

%%

all_H1_rom = zeros(length(rdims), size(H1_fom, 1), 3);
all_H2_rom = zeros(length(rdims), size(H2_fom, 1), 3);
k = 0;

for rdim = rdims
k = k + 1;
load(['md_rom' int2str(rdim) '.mat'])
plotAngleHistogram(H1_rom, H2_rom, ['rom' int2str(rdim)]);
all_H1_rom(k, :, :) = H1_rom;
all_H2_rom(k, :, :) = H2_rom;
end

plotAtomTrajectory(H1_fom(:,1), all_H1_rom(:,:,1), rdims, 'x', 1)
plotAtomTrajectory(H1_fom(:,2), all_H1_rom(:,:,2), rdims, 'y', 1)
plotAtomTrajectory(H1_fom(:,3), all_H1_rom(:,:,3), rdims, 'z', 1)

plotAtomTrajectory(H2_fom(:,1), all_H2_rom(:,:,1), rdims, 'x', 2)
plotAtomTrajectory(H2_fom(:,2), all_H2_rom(:,:,2), rdims, 'y', 2)
plotAtomTrajectory(H2_fom(:,3), all_H2_rom(:,:,3), rdims, 'z', 2)

%%
function plotAtomTrajectory(X_fom, all_X_rom, rdims, var, idx)
figure;
hold on;
plot(X_fom, 'Linewidth', 2, 'DisplayName', 'FOM');
k = 0;
for rdim = rdims
k = k + 1;
X_rom = all_X_rom(k, :);
plot(X_rom, 'Linewidth', 2, 'DisplayName', ['ROM dim = ' int2str(rdim)]);
end
title([var '-coordinate of H' int2str(idx)])
legend;
saveas(gcf, [var '_H' int2str(idx)], 'jpg');
end

function plotAngleHistogram(X1, X2, suffix)
figure;
A = acosd(sum(X1.*X2,2) ./ sqrt(sum(X1.^2,2)) ./ sqrt(sum(X2.^2,2)));
histogram(A, 20);
xlabel('Angle');
ylabel('Frequency');
title('Histogram of angle');
saveas(gcf, ['angle_' suffix], 'jpg');
end
8 changes: 8 additions & 0 deletions src/Control.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2057,6 +2057,8 @@ void Control::setROMOptions(const boost::program_options::variables_map& vm)
rom_pri_option.save_librom_snapshot = vm["ROM.offline.save_librom_snapshot"].as<bool>();
rom_pri_option.librom_snapshot_freq = vm["ROM.offline.librom_snapshot_freq"].as<int>();

rom_pri_option.compare_md = vm["ROM.basis.compare_md"].as<bool>();
rom_pri_option.num_orbbasis = vm["ROM.basis.number_of_orbital_basis"].as<int>();
rom_pri_option.num_potbasis = vm["ROM.basis.number_of_potential_basis"].as<int>();
} // onpe0

Expand Down Expand Up @@ -2106,6 +2108,12 @@ void Control::syncROMOptions()
rom_pri_option.rom_stage = static_cast<ROMStage>(rom_stage);
rom_pri_option.variable = static_cast<ROMVariable>(rom_var);

mpirc = MPI_Bcast(&rom_pri_option.compare_md, 1, MPI_C_BOOL, 0, comm_global_);
bcast_check(mpirc);

mpirc = MPI_Bcast(&rom_pri_option.num_orbbasis, 1, MPI_INT, 0, comm_global_);
bcast_check(mpirc);

mpirc = MPI_Bcast(&rom_pri_option.num_potbasis, 1, MPI_INT, 0, comm_global_);
bcast_check(mpirc);
}
1 change: 1 addition & 0 deletions src/MGmol.h
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,7 @@ class MGmol : public MGmolInterface

#ifdef MGMOL_HAS_LIBROM
int save_orbital_snapshot(std::string snapshot_dir, OrbitalsType& orbitals);
void project_orbital(std::string snapshot_dir, int rdim, OrbitalsType& orbitals);
#endif
};
// Instantiate static variables here to avoid clang warnings
Expand Down
Loading
Loading