Skip to content

Commit b9794dd

Browse files
committed
Merge branch 'upstream-objcryst'
* upstream-objcryst: Move ZScatterer2Molecule to Molecule.h and Molecule.cpp, so it can be used from python
2 parents 068ff56 + 9cf94a7 commit b9794dd

2 files changed

Lines changed: 149 additions & 0 deletions

File tree

src/ObjCryst/ObjCryst/Molecule.cpp

Lines changed: 144 additions & 0 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
@@ -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)