Skip to content

Commit 27d0c39

Browse files
committed
Merge branch 'upstream-objcryst'
* upstream-objcryst: SpaceGroupExplorer: allow keeping or not the tested spacegroup, or the best solution Add Crystal.GetFormula(). Fix same function in Molecule to use symbol and not ScatteringPower name for sorting. Use formula to automatically name Crystal and DiffractionDataSingleCrystal when imported from CIF and no name is given. Rename SpacegroupExplorer to SpaceGroupExplorer for consistency Move Spacegroup explorer in a separate class along PowderPattern, for non-GUI access Correct EstimateCellVolume estimation for orthorombic F Better format for ObjRegistry::Print() # Conflicts: # ObjCryst/wxCryst/wxPowderPattern.cpp
2 parents e326dcb + d5e3585 commit 27d0c39

10 files changed

Lines changed: 470 additions & 24 deletions

File tree

src/ObjCryst/ObjCryst/CIF.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1171,8 +1171,10 @@ Crystal* CreateCrystalFromCIF(CIF &cif,const bool verbose,const bool checkSymAsX
11711171
if(verbose) cout<<endl<<"Finally using spacegroup name:"<<bestsymbol<<endl;
11721172
pCryst->GetSpaceGroup().ChangeSpaceGroup(bestsymbol);
11731173
}
1174+
// Try to set name from CIF. If that fails, the computed formula will be used at the end
11741175
if(pos->second.mName!="") pCryst->SetName(pos->second.mName);
11751176
else if(pos->second.mFormula!="") pCryst->SetName(pos->second.mFormula);
1177+
11761178
const float t1=chrono.seconds();
11771179
(*fpObjCrystInformUser)((boost::format("CIF: Create Crystal:%s(%s)(dt=%6.3fs)")%pCryst->GetName() % pCryst->GetSpaceGroup().GetName() % t1).str());
11781180

@@ -1277,6 +1279,7 @@ Crystal* CreateCrystalFromCIF(CIF &cif,const bool verbose,const bool checkSymAsX
12771279
}
12781280
(*fpObjCrystInformUser)((boost::format("CIF: finished connecting atoms (%u isolated atoms, %u molecules) (Crystal creation=%6.3fs total)") % ctat % ctmol % chrono.seconds()).str());
12791281
}
1282+
if(pCryst->GetName()=="") pCryst->SetName(pCryst->GetFormula());
12801283
}
12811284
return pCryst;
12821285
}
@@ -1299,6 +1302,7 @@ PowderPattern* CreatePowderPatternFromCIF(CIF &cif)
12991302
DiffractionDataSingleCrystal* CreateSingleCrystalDataFromCIF(CIF &cif, Crystal *pcryst)
13001303
{
13011304
DiffractionDataSingleCrystal* pData=NULL;
1305+
std::string name("");
13021306
for(map<string,CIFData>::iterator pos=cif.mvData.begin();pos!=cif.mvData.end();++pos)
13031307
{
13041308
if(pos->second.mH.numElements()>0)
@@ -1310,6 +1314,7 @@ DiffractionDataSingleCrystal* CreateSingleCrystalDataFromCIF(CIF &cif, Crystal *
13101314
{ // Use last Crystal created
13111315
pcryst=&(gCrystalRegistry.GetObj(gCrystalRegistry.GetNb()-1));
13121316
(*fpObjCrystInformUser)((boost::format("CIF: Importing SINGLE CRYSTAL DIFFRACTION data: using last Crystal structure as corresponding crystal [%s]") % pcryst->GetName().c_str()).str());
1317+
name = pcryst->GetName();
13131318
}
13141319
else
13151320
{
@@ -1320,6 +1325,7 @@ DiffractionDataSingleCrystal* CreateSingleCrystalDataFromCIF(CIF &cif, Crystal *
13201325
}
13211326
pData=new DiffractionDataSingleCrystal(*pcryst);
13221327
pData->SetHklIobs(pos->second.mH,pos->second.mK,pos->second.mL,pos->second.mIobs,pos->second.mSigma);
1328+
if(pData->GetName()=="") pData->SetName(name);
13231329
(*fpObjCrystInformUser)((boost::format("CIF: Imported SINGLE CRYSTAL DIFFRACTION data, with %d reflections") % pData->GetNbRefl()).str());
13241330
}
13251331
}

src/ObjCryst/ObjCryst/Crystal.cpp

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,11 +380,41 @@ void Crystal::Print(ostream &os)const
380380
const long genMult=this->GetSpaceGroup().GetNbSymmetrics();
381381
for(int i=0;i<mScattCompList.GetNbComponent();i++)
382382
nbAtoms += genMult * mScattCompList(i).mOccupancy * mScattCompList(i).mDynPopCorr;
383-
os << " Total number of components (atoms) in one unit cell : " << nbAtoms<<endl<<endl;
383+
os << " Total number of components (atoms) in one unit cell : " << nbAtoms<<endl
384+
<< " Chemical formula: "<< this->GetFormula() <<endl;
384385

385386
VFN_DEBUG_MESSAGE("Crystal::Print():End",5)
386387
}
387388

389+
std::string Crystal::GetFormula() const
390+
{
391+
this->GetScatteringComponentList();
392+
if(mScattCompList.GetNbComponent() == 0) return "";
393+
std::map<std::string,float> velts;
394+
for(unsigned int i=0; i<mScattCompList.GetNbComponent(); ++i)
395+
{
396+
const ScatteringComponent* psi = &mScattCompList(i);
397+
if(psi->mpScattPow == 0) continue;
398+
if(psi->mpScattPow->GetClassName().compare("ScatteringPowerAtom")!=0) continue;
399+
const ScatteringPowerAtom *pat=dynamic_cast<const ScatteringPowerAtom*>(psi->mpScattPow);
400+
string p=pat->GetSymbol();
401+
if(velts.count(p)==0)
402+
velts[p] = psi->mOccupancy * psi->mDynPopCorr ;
403+
else velts[p] += psi->mOccupancy * psi->mDynPopCorr;
404+
}
405+
stringstream s;
406+
s<<std::setprecision(2);
407+
for(std::map<std::string,float>::const_iterator pos=velts.begin();pos!=velts.end();++pos)
408+
{
409+
if(pos!=velts.begin()) s<<" ";
410+
float nb=pos->second;
411+
if((abs(nb)-nb)<0.01) s<<pos->first<<int(round(nb));
412+
else s<<pos->first<<nb;
413+
}
414+
return s.str();
415+
}
416+
417+
388418
CrystMatrix_REAL Crystal::GetMinDistanceTable(const REAL minDistance) const
389419
{
390420
VFN_DEBUG_MESSAGE("Crystal::MinDistanceTable()",5)

src/ObjCryst/ObjCryst/Crystal.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,9 @@ class Crystal:public UnitCell
189189
/// \todo one function to print on one line and a PrintLong() function
190190
/// \param os the stream to which the information is outputed (default=cout)
191191
void Print(ostream &os=cout) const;
192+
193+
/// Formula with atoms in alphabetic order
194+
std::string GetFormula() const;
192195

193196
/** \brief Minimum interatomic distance between all scattering components (atoms) in
194197
* the crystal.

src/ObjCryst/ObjCryst/Indexing.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include <time.h>
3131
#include "ObjCryst/RefinableObj/RefinableObj.h"
3232
#include "ObjCryst/RefinableObj/LSQNumObj.h"
33+
#include "ObjCryst/ObjCryst/PowderPattern.h"
3334
namespace ObjCryst
3435
{
3536
/** Different lattice types.

src/ObjCryst/ObjCryst/Molecule.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2180,8 +2180,8 @@ std::string Molecule::GetFormula() const
21802180
if((*pos)->IsDummy()) continue;
21812181
string p=(*pos)->GetScatteringPower().GetSymbol();
21822182
if(velts.count(p)==0)
2183-
velts[(*pos)->GetScatteringPower().GetName()]=(*pos)->GetOccupancy();
2184-
else velts[(*pos)->GetScatteringPower().GetName()]+=(*pos)->GetOccupancy();
2183+
velts[p]=(*pos)->GetOccupancy();
2184+
else velts[p]+=(*pos)->GetOccupancy();
21852185
}
21862186
stringstream s;
21872187
s<<std::setprecision(2);

0 commit comments

Comments
 (0)