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

Enhance PDB File Import to Support Trajectory Data in Avogadro #1659

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
19 changes: 10 additions & 9 deletions avogadro/io/pdbformat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down