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

If a chain ID is missing / invalid, skip (to read non-standard PDB) #647

Merged
merged 1 commit into from
Jul 5, 2021
Merged
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
20 changes: 17 additions & 3 deletions avogadro/io/pdbformat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <avogadro/core/elements.h>
#include <avogadro/core/molecule.h>
#include <avogadro/core/residue.h>
#include <avogadro/core/unitcell.h>
#include <avogadro/core/utilities.h>
#include <avogadro/core/vector.h>

Expand All @@ -23,6 +24,7 @@ using Avogadro::Core::Molecule;
using Avogadro::Core::Residue;
using Avogadro::Core::startsWith;
using Avogadro::Core::trimmed;
using Avogadro::Core::UnitCell;

using std::getline;
using std::istringstream;
Expand Down Expand Up @@ -58,6 +60,20 @@ bool PdbFormat::read(std::istream& in, Core::Molecule& mol)
}
}

// e.g. CRYST1 4.912 4.912 6.696 90.00 90.00 120.00 P1 1
// https://www.wwpdb.org/documentation/file-format-content/format33/sect8.html
else if (startsWith(buffer, "CRYST1")) {
Real a = lexicalCast<Real>(buffer.substr(6, 9), ok);
Real b = lexicalCast<Real>(buffer.substr(15, 9), ok);
Real c = lexicalCast<Real>(buffer.substr(24, 9), ok);
Real alpha = lexicalCast<Real>(buffer.substr(33, 7), ok);
Real beta = lexicalCast<Real>(buffer.substr(40, 7), ok);
Real gamma = lexicalCast<Real>(buffer.substr(47, 8), ok);

Core::UnitCell* cell = new Core::UnitCell(a, b, c, alpha, beta, gamma);
mol.setUnitCell(cell);
}

else if (startsWith(buffer, "ATOM") || startsWith(buffer, "HETATM")) {
// First we initialize the residue instance
size_t residueId = lexicalCast<size_t>(buffer.substr(22, 4), ok);
Expand All @@ -78,9 +94,7 @@ bool PdbFormat::read(std::istream& in, Core::Molecule& mol)

char chainId = lexicalCast<char>(buffer.substr(21, 1), ok);
if (!ok) {
appendError("Failed to parse chain identifier: " +
buffer.substr(21, 1));
return false;
chainId = 'A'; // it's a non-standard "PDB"-like file
}

r = &mol.addResidue(residueName, currentResidueId, chainId);
Expand Down