Skip to content

Commit

Permalink
Fixed error where first plot was not reset when loading a new model
Browse files Browse the repository at this point in the history
  • Loading branch information
guser40 committed Aug 15, 2024
1 parent 6a5de56 commit 4302520
Showing 1 changed file with 24 additions and 22 deletions.
46 changes: 24 additions & 22 deletions src/components/veloxchem/veloxchem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,9 @@ struct VeloxChem : viamd::EventHandler {
double* osc_points;
double* cgs_points;
const char* x_unit;

bool first_plot_rot_ecd = true;
bool first_plot_vib = true;
} rsp;

// Arena for persistent allocations for the veloxchem module (tied to the lifetime of the VLX object)
Expand Down Expand Up @@ -1194,8 +1197,8 @@ struct VeloxChem : viamd::EventHandler {
}
ImGui::EndMenuBar();
}
static bool first_plot1 = true;
if (first_plot1) { ImGui::SetNextItemOpen(true); }

if (rsp.first_plot_rot_ecd) { ImGui::SetNextItemOpen(true); }
if (ImGui::TreeNode("Absorption & ECD")) {
bool refit1 = false;
bool recalculate1 = false;
Expand All @@ -1214,7 +1217,7 @@ struct VeloxChem : viamd::EventHandler {
const double* y_osc_peaks = vlx.rsp.absorption_osc_str;
const double* y_cgs_peaks = vlx.rsp.electronic_circular_dichroism_cgs;

if (first_plot1) {
if (rsp.first_plot_rot_ecd) {
rsp.x_ev_samples = md_array_create(double, num_samples, arena);
rsp.x_unit_samples = md_array_create(double, num_samples, arena);
rsp.x_unit_peaks = md_array_create(double, num_peaks, arena);
Expand Down Expand Up @@ -1254,14 +1257,14 @@ struct VeloxChem : viamd::EventHandler {
break;
}

if (recalculate1 || first_plot1) {
if (recalculate1 || rsp.first_plot_rot_ecd) {
osc_to_eps(rsp.eps, rsp.x_ev_samples, num_samples, y_osc_peaks, vlx.rsp.absorption_ev, num_peaks, distr_func, gamma1 * 2);
rot_to_eps_delta(rsp.ecd, rsp.x_ev_samples, num_samples, y_cgs_peaks, vlx.rsp.absorption_ev, num_peaks, distr_func, gamma1 * 2);
}

static ImPlotRect osc_lim_constraint = {0, 0, 0, 0};
static ImPlotRect cgs_lim_constraint = {0, 0, 0, 0};
if (refit1 || first_plot1) {
if (refit1 || rsp.first_plot_rot_ecd) {
// Do conversions
convert_values(rsp.x_unit_peaks, vlx.rsp.absorption_ev, num_peaks, x_unit);
convert_values(rsp.x_unit_samples, rsp.x_ev_samples, num_samples, x_unit);
Expand All @@ -1278,7 +1281,7 @@ struct VeloxChem : viamd::EventHandler {
}
}

if (first_plot1) {
if (rsp.first_plot_rot_ecd) {
rsp.osc_points = md_array_create(double, num_peaks, arena);
rsp.cgs_points = md_array_create(double, num_peaks, arena);
max_points(rsp.osc_points, y_osc_peaks, num_peaks);
Expand Down Expand Up @@ -1311,20 +1314,20 @@ struct VeloxChem : viamd::EventHandler {
if (ImPlot::BeginSubplots("##AxisLinking", 2, 1, ImVec2(-1, -1), ImPlotSubplotFlags_LinkCols)) {
// Absorption
static double osc_to_eps_mult = 1;
if (recalculate1 || first_plot1) {
if (recalculate1 || rsp.first_plot_rot_ecd) {
osc_to_eps_mult = is_all_zero(y_osc_peaks, num_peaks) ? 1 : axis_conversion_multiplier(y_osc_peaks, rsp.eps, num_peaks, num_samples);
}

static ImPlotRect cur_osc_lims = {0, 1, 0, 1};
if (refit1 || first_plot1) {
if (refit1 || rsp.first_plot_rot_ecd) {
ImPlot::SetNextAxisToFit(ImAxis_X1);
}
if (ImPlot::BeginPlot("Absorption")) {
ImPlot::SetupLegend(ImPlotLocation_NorthEast, ImPlotLegendFlags_None);
ImPlot::SetupAxis(ImAxis_X1, x_unit_str[x_unit]);
ImPlot::SetupAxis(ImAxis_Y1, "f", ImPlotAxisFlags_AuxDefault);
ImPlot::SetupAxis(ImAxis_Y2, (const char*)u8"ε (L mol⁻¹ cm⁻¹)");
if (refit1 || first_plot1) {
if (refit1 || rsp.first_plot_rot_ecd) {
ImPlot::SetupAxisLimits(ImAxis_X1, osc_lim_constraint.X.Min, osc_lim_constraint.X.Max);
ImPlot::SetupAxisLimits(ImAxis_Y1, osc_lim_constraint.Y.Min, osc_lim_constraint.Y.Max);
cur_osc_lims = osc_lim_constraint;
Expand Down Expand Up @@ -1376,11 +1379,11 @@ struct VeloxChem : viamd::EventHandler {

// Rotatory ECD
static double cgs_to_ecd_mult = 1;
if (recalculate1 || first_plot1) {
if (recalculate1 || rsp.first_plot_rot_ecd) {
cgs_to_ecd_mult = is_all_zero(y_cgs_peaks, num_peaks) ? 1 : axis_conversion_multiplier(y_cgs_peaks, rsp.ecd, num_peaks, num_samples);
}
static ImPlotRect cur_cgs_lims = {0, 1, 0, 1};
if (refit1 || first_plot1) {
if (refit1 || rsp.first_plot_rot_ecd) {
ImPlot::SetNextAxisToFit(ImAxis_X1);
}

Expand All @@ -1389,7 +1392,7 @@ struct VeloxChem : viamd::EventHandler {
ImPlot::SetupAxis(ImAxis_X1, x_unit_str[x_unit]);
ImPlot::SetupAxis(ImAxis_Y1, (const char*)u8"R (10⁻⁴⁰ cgs)", ImPlotAxisFlags_AuxDefault);
ImPlot::SetupAxis(ImAxis_Y2, (const char*)u8"Δε(ω) (L mol⁻¹ cm⁻¹)");
if (refit1 || first_plot1) {
if (refit1 || rsp.first_plot_rot_ecd) {
ImPlot::SetupAxisLimits(ImAxis_X1, cgs_lim_constraint.X.Min, cgs_lim_constraint.X.Max);
ImPlot::SetupAxisLimits(ImAxis_Y1, cgs_lim_constraint.Y.Min, cgs_lim_constraint.Y.Max);
cur_cgs_lims = cgs_lim_constraint;
Expand Down Expand Up @@ -1440,12 +1443,11 @@ struct VeloxChem : viamd::EventHandler {
}
ImPlot::EndSubplots();
}
first_plot1 = false;
rsp.first_plot_rot_ecd = false;
ImGui::TreePop();
}

static bool first_plot2 = true;
if (first_plot2) { ImGui::SetNextItemOpen(true); }

if (rsp.first_plot_vib) { ImGui::SetNextItemOpen(true); }
if (ImGui::TreeNode("Vibrational Analysis")) {
// draw the vibrational analysis
double har_freqs[3] = {1562.20, 3663.36, 3677.39};
Expand Down Expand Up @@ -1505,7 +1507,7 @@ struct VeloxChem : viamd::EventHandler {
break;
}

if (first_plot2) {
if (rsp.first_plot_vib) {
rsp.vib_x = md_array_create(double, num_samples, arena);
rsp.vib_y = md_array_create(double, num_samples, arena);

Expand All @@ -1520,11 +1522,11 @@ struct VeloxChem : viamd::EventHandler {
}
}

if (first_plot2 || recalculate2 || refit2) {
if (rsp.first_plot_vib || recalculate2 || refit2) {
general_broadening(rsp.vib_y, rsp.vib_x, num_samples, irs, har_freqs, num_vibs, distr_func, gamma2 * 2);
}

if (first_plot2) {
if (rsp.first_plot_vib) {
rsp.vib_points = md_array_create(double, num_vibs, arena);
max_points(rsp.vib_points, irs, num_vibs);
}
Expand All @@ -1537,7 +1539,7 @@ struct VeloxChem : viamd::EventHandler {
ImPlotAxisFlags y_flag = invert_y ? ImPlotAxisFlags_Invert : 0;

static ImPlotRect lim_constraint = { 0, 0, 0, 0 };
if (refit2 || first_plot2) {
if (refit2 || rsp.first_plot_vib) {
lim_constraint = get_plot_limits(rsp.vib_x, irs, num_vibs, num_samples);
}

Expand All @@ -1546,7 +1548,7 @@ struct VeloxChem : viamd::EventHandler {
ImPlot::SetupLegend(ImPlotLocation_NorthEast, ImPlotLegendFlags_None);
ImPlot::SetupAxis(ImAxis_X1, (const char*)u8"Harmonic Frequency (cm⁻¹)", x_flag);
ImPlot::SetupAxis(ImAxis_Y1, "IR Intensity (km/mol)", y_flag);
if (refit2 || first_plot2) {
if (refit2 || rsp.first_plot_vib) {
ImPlot::SetupAxisLimits(ImAxis_X1, lim_constraint.X.Min, lim_constraint.X.Max);
ImPlot::SetupAxisLimits(ImAxis_Y1, lim_constraint.Y.Min, lim_constraint.Y.Max);
}
Expand Down Expand Up @@ -1605,7 +1607,7 @@ struct VeloxChem : viamd::EventHandler {
state.mold.dirty_buffers |= MolBit_DirtyPosition | MolBit_ClearVelocity;
coord_modified = false;
}
first_plot2 = false;
rsp.first_plot_vib = false;
ImPlot::EndPlot();
}

Expand Down

0 comments on commit 4302520

Please sign in to comment.