Skip to content

Commit f60cf2e

Browse files
committed
Merge remote-tracking branch 'objcryst/master' into upstream-objcryst
* objcryst/master: Better GetFormula for Crystal and Molecule
2 parents 983738a + 760caad commit f60cf2e

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

ObjCryst/ObjCryst/Crystal.cpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,11 @@ std::string Crystal::GetFormula() const
409409
{
410410
if(pos!=velts.begin()) s<<" ";
411411
float nb=pos->second;
412-
if(abs(round(nb)-nb)<0.005) s<<pos->first<<int(round(nb));
412+
if(abs(round(nb)-nb)<0.005)
413+
{
414+
if(int(round(nb))==1) s<<pos->first;
415+
else s<<pos->first<<int(round(nb));
416+
}
413417
else s<<pos->first<<nb;
414418
}
415419
return s.str();

ObjCryst/ObjCryst/Molecule.cpp

+7-2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include <iterator>
2525
#include <algorithm>
2626
#include <iomanip>
27+
#include <ctime>
2728

2829
#include "ObjCryst/Quirks/VFNStreamFormat.h"
2930
#include "ObjCryst/ObjCryst/Molecule.h"
@@ -2206,8 +2207,12 @@ std::string Molecule::GetFormula() const
22062207
{
22072208
if(pos!=velts.begin()) s<<" ";
22082209
float nb=pos->second;
2209-
if((abs(nb)-nb)<0.01) s<<pos->first<<int(round(nb));
2210-
else s<<pos->first<<nb;
2210+
if(abs(round(nb)-nb)<0.005)
2211+
{
2212+
if(int(round(nb))==1) s<<pos->first;
2213+
else s<<pos->first<<int(round(nb));
2214+
}
2215+
else s<<pos->first<<nb;
22112216
}
22122217
return s.str();
22132218
}

0 commit comments

Comments
 (0)