Skip to content

Commit c0a6bb8

Browse files
committed
CreateCrystalFromCIF: enable to supply a Crystal pointer to import the first structure into an existing Crystal
1 parent 096002e commit c0a6bb8

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

ObjCryst/ObjCryst/CIF.cpp

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1001,16 +1001,20 @@ Crystal* CreateCrystalFromCIF(CIF &cif,bool verbose,bool checkSymAsXYZ)
10011001
return CreateCrystalFromCIF(cif,verbose,checkSymAsXYZ,false,false);
10021002
}
10031003

1004-
Crystal* CreateCrystalFromCIF(CIF &cif,const bool verbose,const bool checkSymAsXYZ, const bool oneScatteringPowerPerElement, const bool connectAtoms)
1004+
Crystal* CreateCrystalFromCIF(CIF &cif,const bool verbose,const bool checkSymAsXYZ,
1005+
const bool oneScatteringPowerPerElement, const bool connectAtoms,
1006+
Crystal *pCryst)
10051007
{
10061008
(*fpObjCrystInformUser)("CIF: Opening CIF");
10071009
Chronometer chrono;
10081010
chrono.start();
1009-
1011+
10101012
// If oneScatteringPowerPerElement==true, we hold this to compute the average Biso per element
10111013
std::map<ScatteringPower*,std::pair<REAL,unsigned int> > vElementBiso;
1012-
1013-
Crystal *pCryst=NULL;
1014+
1015+
bool import_multiple = true;
1016+
if(pCryst!=NULL) import_multiple = false;
1017+
10141018
for(map<string,CIFData>::iterator pos=cif.mvData.begin();pos!=cif.mvData.end();++pos)
10151019
if(pos->second.mvLatticePar.size()==6)
10161020
{
@@ -1092,8 +1096,12 @@ Crystal* CreateCrystalFromCIF(CIF &cif,const bool verbose,const bool checkSymAsX
10921096
<<"-> "<<spg
10931097
<<endl;
10941098
(*fpObjCrystInformUser)("CIF: Create Crystal=");
1095-
pCryst=new Crystal(pos->second.mvLatticePar[0],pos->second.mvLatticePar[1],pos->second.mvLatticePar[2],
1096-
pos->second.mvLatticePar[3],pos->second.mvLatticePar[4],pos->second.mvLatticePar[5],spg);
1099+
if(pCryst==NULL)
1100+
pCryst=new Crystal(pos->second.mvLatticePar[0],pos->second.mvLatticePar[1],pos->second.mvLatticePar[2],
1101+
pos->second.mvLatticePar[3],pos->second.mvLatticePar[4],pos->second.mvLatticePar[5],spg);
1102+
else
1103+
pCryst->Init(pos->second.mvLatticePar[0],pos->second.mvLatticePar[1],pos->second.mvLatticePar[2],
1104+
pos->second.mvLatticePar[3],pos->second.mvLatticePar[4],pos->second.mvLatticePar[5],spg, "");
10971105
if( (pos->second.mSpacegroupSymbolHall=="")
10981106
&&(pos->second.mvSymmetry_equiv_pos_as_xyz.size()>0)
10991107
&&(pos->second.mSpacegroupHermannMauguin!="")
@@ -1280,6 +1288,7 @@ Crystal* CreateCrystalFromCIF(CIF &cif,const bool verbose,const bool checkSymAsX
12801288
(*fpObjCrystInformUser)((boost::format("CIF: finished connecting atoms (%u isolated atoms, %u molecules) (Crystal creation=%6.3fs total)") % ctat % ctmol % chrono.seconds()).str());
12811289
}
12821290
if(pCryst->GetName()=="") pCryst->SetName(pCryst->GetFormula());
1291+
if(!import_multiple) return pCryst;
12831292
}
12841293
return pCryst;
12851294
}

ObjCryst/ObjCryst/CIF.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,11 +210,16 @@ Crystal* CreateCrystalFromCIF(CIF &cif,const bool verbose=true,const bool checkS
210210
* e.g. when importing CIFs obtained from single crystal data refinement.
211211
* \param connectAtoms: if true, call Crystal::ConnectAtoms to try to create as many Molecules
212212
* as possible from the list of imported atoms.
213+
* \param pcryst: a pointer to an existing Crystal can be given. In this case,
214+
* only the first Crystal structure found is imported from the CIF. The given
215+
* Crystal is assumed to be empty.
213216
* \warning The behaviour of oneScatteringPowerPerElement has changed [2016/11/11]:
214217
* when set to false, it will return one scattering power per atom, where as prior to this
215218
* change, scattering powers where identical for identical Debye-Waller factors.
216219
*/
217-
Crystal* CreateCrystalFromCIF(CIF &cif,const bool verbose,const bool checkSymAsXYZ, const bool oneScatteringPowerPerElement, const bool connectAtoms);
220+
Crystal* CreateCrystalFromCIF(CIF &cif,const bool verbose,const bool checkSymAsXYZ,
221+
const bool oneScatteringPowerPerElement, const bool connectAtoms,
222+
Crystal *pcryst=NULL);
218223

219224
/// Create PowderPattern object(s) from a CIF, if possible.
220225
/// Returns a null pointer if no pattern could be extracted.

0 commit comments

Comments
 (0)