Skip to content

Commit

Permalink
Add support for Hall number and space group to CJSON read/write
Browse files Browse the repository at this point in the history
Signed-off-by: Geoff Hutchison <[email protected]>
  • Loading branch information
ghutchis committed Nov 4, 2023
1 parent 49c2b88 commit df60754
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions avogadro/io/cjsonformat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,16 @@ bool CjsonFormat::read(std::istream& file, Molecule& molecule)
}
if (unitCellObject != nullptr)
molecule.setUnitCell(unitCellObject);

// check for Hall number if present
if (unitCell["hallNumber"].is_number()) {
if (hallNumber > 0 && hallNumber < 531)
molecule.setHallNumber(static_cast<int>(unitCell["hallNumber"]));
} else if (unitCell["spaceGroup"].is_string()) {
auto hallNumber = SpaceGroups::hallNumber(unitCell["spaceGroup"]);
if (hallNumber != -1 && hallNumber != 0)
molecule.setHallNumber(hallNumber);
}
}

json fractional = atoms["coords"]["3dFractional"];
Expand Down Expand Up @@ -699,6 +709,10 @@ bool CjsonFormat::write(std::ostream& file, const Molecule& molecule)
vectors.push_back(molecule.unitCell()->cVector().z());
unitCell["cellVectors"] = vectors;

// write the Hall number and space group
unitCell["hallNumber"] = molecule.hallNumber();
unitCell["spaceGroup"] = SpaceGroups::international(molecule.hallNumber());

root["unitCell"] = unitCell;
}

Expand Down

0 comments on commit df60754

Please sign in to comment.