Skip to content

Commit 6b27fa3

Browse files
authored
Merge pull request #11 from vincefn/master
Merge upstream objcryst changes
2 parents 0547acb + 9884aa8 commit 6b27fa3

14 files changed

Lines changed: 649 additions & 83 deletions

src/ObjCryst/ObjCryst/CIF.cpp

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,7 @@ void CIFData::ExtractPowderPattern(const bool verbose)
477477
{
478478
mWavelength=CIFNumeric2REAL(positem->second);
479479
defaultWavelength=mWavelength;
480-
cout<<"Found wavelength:"<<defaultWavelength<<endl;
480+
if(verbose) cout<<"Found wavelength:"<<defaultWavelength<<endl;
481481
}
482482
else mWavelength=defaultWavelength;
483483

@@ -490,10 +490,10 @@ void CIFData::ExtractPowderPattern(const bool verbose)
490490
pos_wavelength=loop->second.find("_diffrn_radiation_wavelength");
491491
if(pos_wavelength!=loop->second.end())
492492
{
493-
cout<<"Found wavelength (in loop):"<<pos_wavelength->second[0];
493+
if(verbose) cout<<"Found wavelength (in loop):"<<pos_wavelength->second[0];
494494
mWavelength=CIFNumeric2REAL(pos_wavelength->second[0]);
495495
defaultWavelength=mWavelength;
496-
cout<<" -> "<<defaultWavelength<<endl;
496+
if(verbose) cout<<" -> "<<defaultWavelength<<endl;
497497
}
498498

499499
pos_iobs=loop->second.find("_pd_meas_counts_total");
@@ -580,7 +580,7 @@ void CIFData::ExtractSingleCrystalData(const bool verbose)
580580
{
581581
mWavelength=CIFNumeric2REAL(positem->second);
582582
defaultWavelength=mWavelength;
583-
cout<<"Found wavelength:"<<defaultWavelength<<endl;
583+
if(verbose) cout<<"Found wavelength:"<<defaultWavelength<<endl;
584584
}
585585
else mWavelength=defaultWavelength;
586586

@@ -593,10 +593,10 @@ void CIFData::ExtractSingleCrystalData(const bool verbose)
593593
pos_wavelength=loop->second.find("_diffrn_radiation_wavelength");
594594
if(pos_wavelength!=loop->second.end())
595595
{
596-
cout<<"Found wavelength (in loop):"<<pos_wavelength->second[0];
596+
if(verbose) cout<<"Found wavelength (in loop):"<<pos_wavelength->second[0];
597597
mWavelength=CIFNumeric2REAL(pos_wavelength->second[0]);
598598
defaultWavelength=mWavelength;
599-
cout<<" -> "<<defaultWavelength<<endl;
599+
if(verbose) cout<<" -> "<<defaultWavelength<<endl;
600600
}
601601

602602
pos_iobs=loop->second.find("_refln_F_squared_meas");
@@ -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;
10121014

1013-
Crystal *pCryst=NULL;
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
}

src/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.

src/ObjCryst/ObjCryst/Crystal.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -732,7 +732,6 @@ void Crystal::GLInitDisplayList(const bool onlyIndependentAtoms,
732732
displayEnantiomer,displayNames,hideHydrogens,fadeDistance,fullMoleculeInLimits);
733733
}
734734
glPopMatrix();
735-
cout << "Crystal::GLView(): Compiled without OpenGL support !" <<endl;
736735
VFN_DEBUG_EXIT("Crystal::GLInitDisplayList(bool)",5)
737736
}
738737
#endif // OBJCRYST_GL

src/ObjCryst/ObjCryst/IO.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ void XMLCrystFileSaveGlobal(ostream &out)
123123
char strDate[40];
124124
strftime(strDate,sizeof(strDate),"%Y-%m-%dT%H:%M:%S%Z",gmtime(&date));//%Y-%m-%dT%H:%M:%S%Z
125125
tag.AddAttribute("Date",strDate);
126-
tag.AddAttribute("Revision","2017002");
126+
tag.AddAttribute("Revision","2021001");
127127
out<<tag<<endl;
128128

129129
for(int i=0;i<gCrystalRegistry.GetNb();i++)
@@ -2001,6 +2001,11 @@ void PowderPattern::XMLOutput(ostream &os,int indent)const
20012001
this->GetPar(&m2ThetaTransparency).XMLOutput(os,"2ThetaTransparency",indent);
20022002
os <<endl;
20032003
}
2004+
if(mMuR>0)
2005+
{
2006+
this->GetPar(&mMuR).XMLOutput(os,"MuR",indent);
2007+
os <<endl;
2008+
}
20042009

20052010
for(unsigned int i=0;i<this->GetNbOption();i++)
20062011
{
@@ -2134,6 +2139,11 @@ void PowderPattern::XMLInput(istream &is,const XMLCrystTag &tagg)
21342139
this->GetPar(&mDIFA).XMLInput(is,tag);
21352140
break;
21362141
}
2142+
if("MuR"==tag.GetAttributeValue(i))
2143+
{
2144+
this->GetPar(&mMuR).XMLInput(is,tag);
2145+
break;
2146+
}
21372147
}
21382148
}
21392149
continue;

src/ObjCryst/ObjCryst/Molecule.cpp

Lines changed: 147 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
#include "ObjCryst/Quirks/VFNStreamFormat.h"
3030
#include "ObjCryst/ObjCryst/Molecule.h"
31+
#include "ObjCryst/ObjCryst/ZScatterer.h"
3132
#include "ObjCryst/RefinableObj/GlobalOptimObj.h"
3233

3334
#ifdef OBJCRYST_GL
@@ -3792,9 +3793,9 @@ void Molecule::GLInitDisplayList(const bool onlyIndependentAtoms,
37923793
}
37933794
}
37943795
const float f=(mvpBond[k]->GetAtom1().GetOccupancy()+mvpBond[k]->GetAtom2().GetOccupancy())/2*this->GetOccupancy();
3795-
const GLfloat colour_bondnonfree[]= { 0.2*fout, .2*fout, .2*fout, f*fout };
3796-
const GLfloat colour_bondrigid[]= { 0.5*fout, .3*fout, .3*fout, f*fout };
3797-
const GLfloat colour_bondfree[]= { 0.8*fout, .8*fout, .8*fout, f*fout };
3796+
const GLfloat colour_bondnonfree[]= { 0.2f*fout, .2f*fout, .2f*fout, f*fout };
3797+
const GLfloat colour_bondrigid[]= { 0.5f*fout, .3f*fout, .3f*fout, f*fout };
3798+
const GLfloat colour_bondfree[]= { 0.8f*fout, .8f*fout, .8f*fout, f*fout };
37983799
if(isRigidGroup)
37993800
glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE,colour_bondrigid);
38003801
else
@@ -7904,4 +7905,147 @@ WXCrystObjBasic* Molecule::WXCreate(wxWindow* parent)
79047905
}
79057906
#endif
79067907

7908+
7909+
Molecule *ZScatterer2Molecule(ZScatterer *scatt)
7910+
{
7911+
VFN_DEBUG_ENTRY("ZScatterer2Molecule()",6)
7912+
Molecule *mol=new Molecule(scatt->GetCrystal(),scatt->GetName());
7913+
const unsigned long nb=scatt->GetZAtomRegistry().GetNb();
7914+
REAL x0=0,y0=0,z0=0;
7915+
for(unsigned int i=0;i<nb;++i)
7916+
{
7917+
const REAL x=scatt->GetZAtomX(i);
7918+
const REAL y=scatt->GetZAtomY(i);
7919+
const REAL z=scatt->GetZAtomZ(i);
7920+
x0+=x;
7921+
y0+=y;
7922+
z0+=z;
7923+
mol->AddAtom(x,y,z,scatt->GetZAtomRegistry().GetObj(i).GetScatteringPower(),
7924+
scatt->GetZAtomRegistry().GetObj(i).GetName());
7925+
7926+
#if 0
7927+
if(i>0)
7928+
{
7929+
const RefinablePar* pLength=&(scatt->GetPar(&(scatt->GetZAtomRegistry()
7930+
.GetObj(i).GetZBondLength())));
7931+
if(pLength->IsFixed())
7932+
mol->AddBond(mol->GetAtom(i),mol->GetAtom(scatt->GetZBondAtom(i)),
7933+
pLength->GetValue(),.01,.02,false);
7934+
else
7935+
if(pLength->IsLimited())
7936+
mol->AddBond(mol->GetAtom(i),mol->GetAtom(scatt->GetZBondAtom(i)),
7937+
(pLength->GetMin()+pLength->GetMax())/2.,.01,.02,false);
7938+
}
7939+
if(i>1)
7940+
{
7941+
const RefinablePar* pAngle=&(scatt->GetPar(&(scatt->GetZAtomRegistry()
7942+
.GetObj(i).GetZAngle())));
7943+
if(pAngle->IsFixed())
7944+
mol->AddBondAngle(mol->GetAtom(i),mol->GetAtom(scatt->GetZBondAtom(i)),
7945+
mol->GetAtom(scatt->GetZAngleAtom(i)),
7946+
pAngle->GetValue(),.01,.02,false);
7947+
else
7948+
if(pAngle->IsLimited())
7949+
mol->AddBondAngle(mol->GetAtom(i),mol->GetAtom(scatt->GetZBondAtom(i)),
7950+
mol->GetAtom(scatt->GetZAngleAtom(i)),
7951+
(pAngle->GetMin()+pAngle->GetMax())/2.,.01,.02,false);
7952+
}
7953+
if(i>2)
7954+
{
7955+
const RefinablePar* pDihed=&(scatt->GetPar(&(scatt->GetZAtomRegistry()
7956+
.GetObj(i).GetZDihedralAngle())));
7957+
MolAtom *p1=&(mol->GetAtom(i));
7958+
MolAtom *p2=&(mol->GetAtom(scatt->GetZBondAtom(i)));
7959+
MolAtom *p3=&(mol->GetAtom(scatt->GetZAngleAtom(i)));
7960+
MolAtom *p4=&(mol->GetAtom(scatt->GetZDihedralAngleAtom(i)));
7961+
if( (fabs(GetBondAngle(*p1,*p2,*p3)-M_PI)>0.3)
7962+
&&(fabs(GetBondAngle(*p1,*p2,*p4)-M_PI)>0.3)
7963+
&&(fabs(GetBondAngle(*p1,*p3,*p4)-M_PI)>0.3)
7964+
&&(fabs(GetBondAngle(*p2,*p3,*p4)-M_PI)>0.3))
7965+
{
7966+
if(pDihed->IsFixed())
7967+
mol->AddDihedralAngle(*p1,*p2,*p3,*p4,pDihed->GetValue(),.01,.02,false);
7968+
else
7969+
if(((pDihed->GetMax()-pDihed->GetMax())<0.3)&&(i>2)&&(pDihed->IsLimited()))
7970+
mol->AddDihedralAngle(*p1,*p2,*p3,*p4,
7971+
(pDihed->GetMin()+pDihed->GetMax())/2.,.01,.02,false);
7972+
}
7973+
}
7974+
#endif
7975+
mol->GetAtom(i).SetOccupancy(scatt->GetZAtomRegistry().GetObj(i).GetOccupancy());
7976+
}
7977+
7978+
CrystVector_REAL x(nb),y(nb),z(nb),radius(nb);
7979+
vector<pair<const ScatteringPowerAtom *,long> > scattpow(nb);
7980+
for(unsigned int i=0;i<nb;++i)
7981+
{
7982+
x(i)=mol->GetAtom(i).GetX();
7983+
y(i)=mol->GetAtom(i).GetY();
7984+
z(i)=mol->GetAtom(i).GetZ();
7985+
if(mol->GetAtom(i).IsDummy())
7986+
{
7987+
radius(i)=-1;
7988+
scattpow[i].first=0;
7989+
}
7990+
else
7991+
{
7992+
radius(i)=mol->GetAtom(i).GetScatteringPower().GetRadius();
7993+
scattpow[i].first=dynamic_cast<const ScatteringPowerAtom *>
7994+
(&(mol->GetAtom(i).GetScatteringPower()));
7995+
scattpow[i].second=scattpow[i].first->GetAtomicNumber();
7996+
}
7997+
}
7998+
for(unsigned int i=0;i<nb;++i)
7999+
{
8000+
if(scattpow[i].first==0) continue;
8001+
const REAL x1=x(i),y1=y(i),z1=z(i);
8002+
x += -x1;
8003+
y += -y1;
8004+
z += -z1;
8005+
for(unsigned int j=i+1;j<nb;++j)
8006+
{
8007+
if(scattpow[j].first==0) continue;
8008+
const REAL dist=sqrt(x(j)*x(j)+y(j)*y(j)+z(j)*z(j));
8009+
//cout<<" -> d="<<dist<<"("<<radius(i)<<","<<radius(j)<<"):"<<scattpow[i].second<<","<<scattpow[j].second<<endl;
8010+
if(dist<(1.10*(radius(i)+radius(j))))
8011+
{
8012+
if((1!=scattpow[i].second)||(1!=scattpow[j].second))
8013+
{
8014+
mol->AddBond(mol->GetAtom(i),mol->GetAtom(j),dist,.01,.02,false);
8015+
}
8016+
}
8017+
}
8018+
x += x1;
8019+
y += y1;
8020+
z += z1;
8021+
}
8022+
mol->BuildConnectivityTable();
8023+
for(map<MolAtom*,set<MolAtom*> >::const_iterator pos=mol->GetConnectivityTable().begin();
8024+
pos!=mol->GetConnectivityTable().end();++pos)
8025+
{
8026+
for(set<MolAtom*>::const_iterator pos1=pos->second.begin();
8027+
pos1!=pos->second.end();++pos1)
8028+
{
8029+
for(set<MolAtom*>::const_iterator pos2=pos1;
8030+
pos2!=pos->second.end();++pos2)
8031+
{
8032+
if(pos2==pos1) continue;
8033+
if(mol->FindBondAngle(**pos1,*(pos->first),**pos2)== mol->GetBondAngleList().end())
8034+
mol->AddBondAngle(**pos1,*(pos->first),**pos2,
8035+
GetBondAngle(**pos1,*(pos->first),**pos2),0.01,0.02,false);
8036+
}
8037+
}
8038+
}
8039+
x0 /= nb;
8040+
y0 /= nb;
8041+
z0 /= nb;
8042+
mol->GetCrystal().OrthonormalToFractionalCoords(x0,y0,z0);
8043+
mol->SetX(x0);
8044+
mol->SetY(y0);
8045+
mol->SetZ(z0);
8046+
mol->UpdateDisplay();
8047+
VFN_DEBUG_EXIT("ZScatterer2Molecule()",6)
8048+
return mol;
8049+
}
8050+
79078051
}//namespace

src/ObjCryst/ObjCryst/Molecule.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1432,6 +1432,11 @@ void ExpandAtomGroupRecursive(MolAtom* atom,
14321432
const map<MolAtom*,set<MolAtom*> > &connect,
14331433
map<MolAtom*,unsigned long> &atomlist,const unsigned long maxdepth, unsigned long depth=0);
14341434

1435+
// Forward declaration
1436+
class ZScatterer;
1437+
1438+
/// Converter from ZScatterer to a Molecule object
1439+
Molecule *ZScatterer2Molecule(ZScatterer *scatt);
14351440

14361441
}//namespace
14371442
#endif

0 commit comments

Comments
 (0)