Skip to content

Commit

Permalink
Fix everything
Browse files Browse the repository at this point in the history
Signed-off-by: Geoff Hutchison <[email protected]>
  • Loading branch information
ghutchis committed Nov 13, 2023
1 parent a2d876c commit 838c3a9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
16 changes: 12 additions & 4 deletions avogadro/io/cjsonformat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,12 @@ bool CjsonFormat::read(std::istream& file, Molecule& molecule)

bool CjsonFormat::deserialize(std::istream& file, Molecule& molecule, bool isJson)
{
json jsonRoot = json::parse(file, nullptr, false);
json jsonRoot;
if (isJson)
jsonRoot = json::parse(file, nullptr, false);
else // msgpack
jsonRoot = json::from_msgpack(file);

if (jsonRoot.is_discarded()) {
appendError("Error reading CJSON file.");
return false;
Expand Down Expand Up @@ -1025,7 +1030,8 @@ bool CjsonFormat::serialize(std::ostream& file, const Molecule& molecule, bool i
modes.push_back(static_cast<unsigned int>(i) + 1);
freqs.push_back(molecule.vibrationFrequencies()[i]);
inten.push_back(molecule.vibrationIRIntensities()[i]);
raman.push_back(molecule.vibrationRamanIntensities()[i]);
if (molecule.vibrationRamanIntensities().size() > i)
raman.push_back(molecule.vibrationRamanIntensities()[i]);
Core::Array<Vector3> atomDisplacements = molecule.vibrationLx(i);
json eigenVector;
for (auto pos : atomDisplacements) {
Expand All @@ -1038,7 +1044,8 @@ bool CjsonFormat::serialize(std::ostream& file, const Molecule& molecule, bool i
root["vibrations"]["modes"] = modes;
root["vibrations"]["frequencies"] = freqs;
root["vibrations"]["intensities"] = inten;
root["vibrations"]["ramanIntensities"] = raman;
if (molecule.vibrationRamanIntensities().size() > 0)
root["vibrations"]["ramanIntensities"] = raman;
root["vibrations"]["eigenVectors"] = eigenVectors;
}

Expand Down Expand Up @@ -1071,8 +1078,9 @@ bool CjsonFormat::serialize(std::ostream& file, const Molecule& molecule, bool i

if (isJson)
file << std::setw(2) << root;
else // write msgpack
else { // write msgpack
json::to_msgpack(root, file);
}

return true;
}
Expand Down
1 change: 0 additions & 1 deletion avogadro/io/cmsgpackformat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ vector<std::string> CMsgPackFormat::mimeTypes() const

bool CMsgPackFormat::write(std::ostream& out, const Core::Molecule& molecule)
{
std::cerr << "CMsgPackFormat::write" << std::endl;
return CjsonFormat::serialize(out, molecule, false);
}

Expand Down

0 comments on commit 838c3a9

Please sign in to comment.