From 7d9b464016d3a102e023be917b398144d26d8352 Mon Sep 17 00:00:00 2001 From: Vinayakjeet Singh Karki <139736674+vinayakjeet@users.noreply.github.com> Date: Sat, 30 Mar 2024 10:01:33 +0530 Subject: [PATCH] transfer Signed-off-by: Vinayakjeet Singh Karki <139736674+vinayakjeet@users.noreply.github.com> --- avogadro/io/pdbformat.cpp | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/avogadro/io/pdbformat.cpp b/avogadro/io/pdbformat.cpp index db6ec85bcb..c3a2c8ff02 100644 --- a/avogadro/io/pdbformat.cpp +++ b/avogadro/io/pdbformat.cpp @@ -58,14 +58,12 @@ bool PdbFormat::read(std::istream& in, Core::Molecule& mol) while (getline(in, buffer)) { // Read Each line one by one - if (startsWith(buffer, "ENDMDL")) { - if (coordSet == 0) { - mol.setCoordinate3d(mol.atomPositions3d(), coordSet++); - positions.reserve(mol.atomCount()); - } else { - mol.setCoordinate3d(positions, coordSet++); - positions.clear(); - } + if (startsWith(buffer, "ENDMDL")) { + // Ensure positions array is not empty before creating a new frame + if (!positions.empty()) { + mol.setCoordinate3d(positions, coordSet++); + positions.clear(); // Clear positions after adding them as a frame + } } // e.g. CRYST1 4.912 4.912 6.696 90.00 90.00 120.00 P1 1 @@ -245,7 +243,10 @@ bool PdbFormat::read(std::istream& in, Core::Molecule& mol) } } } // End while loop - +if (!positions.empty()) { + // This handles the last set of positions if the file doesn't end with ENDMDL + mol.setCoordinate3d(positions, coordSet); +} int count = mol.coordinate3dCount() ? mol.coordinate3dCount() : 1; for (int c = 0; c < count; ++c) { for (char l : altLocs) {