Skip to content

Commit 9cf94a7

Browse files
committed
Move ZScatterer2Molecule to Molecule.h and Molecule.cpp, so it could be used from python
1 parent 303d50c commit 9cf94a7

5 files changed

Lines changed: 150 additions & 147 deletions

File tree

ObjCryst/ObjCryst/Molecule.cpp

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
#include "ObjCryst/Quirks/VFNStreamFormat.h"
2929
#include "ObjCryst/ObjCryst/Molecule.h"
30+
#include "ObjCryst/ObjCryst/ZScatterer.h"
3031
#include "ObjCryst/RefinableObj/GlobalOptimObj.h"
3132

3233
#ifdef OBJCRYST_GL
@@ -7903,4 +7904,147 @@ WXCrystObjBasic* Molecule::WXCreate(wxWindow* parent)
79037904
}
79047905
#endif
79057906

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

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

ObjCryst/wxCryst/wxCrystal.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,6 @@ GLvoid crystGLPrint(const string &s)
138138
glEnable (GL_BLEND);
139139
}
140140

141-
/// Conversion from ZScatterer to the newer Molecule object. (in WXZScatterer.cpp)
142-
Molecule *ZScatterer2Molecule(ZScatterer *scatt);
143-
144141
// dialog to get a bounding box
145142
class UserSelectBoundingBox : public wxDialog {
146143
public:

ObjCryst/wxCryst/wxZScatterer.cpp

Lines changed: 0 additions & 144 deletions
Original file line numberDiff line numberDiff line change
@@ -45,150 +45,6 @@
4545

4646
namespace ObjCryst
4747
{
48-
/// Conversion from ZScatterer to the newer Molecule object.
49-
Molecule *ZScatterer2Molecule(ZScatterer *scatt);
50-
51-
Molecule *ZScatterer2Molecule(ZScatterer *scatt)
52-
{
53-
VFN_DEBUG_ENTRY("ZScatterer2Molecule()",6)
54-
Molecule *mol=new Molecule(scatt->GetCrystal(),scatt->GetName());
55-
const unsigned long nb=scatt->GetZAtomRegistry().GetNb();
56-
REAL x0=0,y0=0,z0=0;
57-
for(unsigned int i=0;i<nb;++i)
58-
{
59-
const REAL x=scatt->GetZAtomX(i);
60-
const REAL y=scatt->GetZAtomY(i);
61-
const REAL z=scatt->GetZAtomZ(i);
62-
x0+=x;
63-
y0+=y;
64-
z0+=z;
65-
mol->AddAtom(x,y,z,scatt->GetZAtomRegistry().GetObj(i).GetScatteringPower(),
66-
scatt->GetZAtomRegistry().GetObj(i).GetName());
67-
68-
#if 0
69-
if(i>0)
70-
{
71-
const RefinablePar* pLength=&(scatt->GetPar(&(scatt->GetZAtomRegistry()
72-
.GetObj(i).GetZBondLength())));
73-
if(pLength->IsFixed())
74-
mol->AddBond(mol->GetAtom(i),mol->GetAtom(scatt->GetZBondAtom(i)),
75-
pLength->GetValue(),.01,.02,false);
76-
else
77-
if(pLength->IsLimited())
78-
mol->AddBond(mol->GetAtom(i),mol->GetAtom(scatt->GetZBondAtom(i)),
79-
(pLength->GetMin()+pLength->GetMax())/2.,.01,.02,false);
80-
}
81-
if(i>1)
82-
{
83-
const RefinablePar* pAngle=&(scatt->GetPar(&(scatt->GetZAtomRegistry()
84-
.GetObj(i).GetZAngle())));
85-
if(pAngle->IsFixed())
86-
mol->AddBondAngle(mol->GetAtom(i),mol->GetAtom(scatt->GetZBondAtom(i)),
87-
mol->GetAtom(scatt->GetZAngleAtom(i)),
88-
pAngle->GetValue(),.01,.02,false);
89-
else
90-
if(pAngle->IsLimited())
91-
mol->AddBondAngle(mol->GetAtom(i),mol->GetAtom(scatt->GetZBondAtom(i)),
92-
mol->GetAtom(scatt->GetZAngleAtom(i)),
93-
(pAngle->GetMin()+pAngle->GetMax())/2.,.01,.02,false);
94-
}
95-
if(i>2)
96-
{
97-
const RefinablePar* pDihed=&(scatt->GetPar(&(scatt->GetZAtomRegistry()
98-
.GetObj(i).GetZDihedralAngle())));
99-
MolAtom *p1=&(mol->GetAtom(i));
100-
MolAtom *p2=&(mol->GetAtom(scatt->GetZBondAtom(i)));
101-
MolAtom *p3=&(mol->GetAtom(scatt->GetZAngleAtom(i)));
102-
MolAtom *p4=&(mol->GetAtom(scatt->GetZDihedralAngleAtom(i)));
103-
if( (fabs(GetBondAngle(*p1,*p2,*p3)-M_PI)>0.3)
104-
&&(fabs(GetBondAngle(*p1,*p2,*p4)-M_PI)>0.3)
105-
&&(fabs(GetBondAngle(*p1,*p3,*p4)-M_PI)>0.3)
106-
&&(fabs(GetBondAngle(*p2,*p3,*p4)-M_PI)>0.3))
107-
{
108-
if(pDihed->IsFixed())
109-
mol->AddDihedralAngle(*p1,*p2,*p3,*p4,pDihed->GetValue(),.01,.02,false);
110-
else
111-
if(((pDihed->GetMax()-pDihed->GetMax())<0.3)&&(i>2)&&(pDihed->IsLimited()))
112-
mol->AddDihedralAngle(*p1,*p2,*p3,*p4,
113-
(pDihed->GetMin()+pDihed->GetMax())/2.,.01,.02,false);
114-
}
115-
}
116-
#endif
117-
mol->GetAtom(i).SetOccupancy(scatt->GetZAtomRegistry().GetObj(i).GetOccupancy());
118-
}
119-
120-
CrystVector_REAL x(nb),y(nb),z(nb),radius(nb);
121-
vector<pair<const ScatteringPowerAtom *,long> > scattpow(nb);
122-
for(unsigned int i=0;i<nb;++i)
123-
{
124-
x(i)=mol->GetAtom(i).GetX();
125-
y(i)=mol->GetAtom(i).GetY();
126-
z(i)=mol->GetAtom(i).GetZ();
127-
if(mol->GetAtom(i).IsDummy())
128-
{
129-
radius(i)=-1;
130-
scattpow[i].first=0;
131-
}
132-
else
133-
{
134-
radius(i)=mol->GetAtom(i).GetScatteringPower().GetRadius();
135-
scattpow[i].first=dynamic_cast<const ScatteringPowerAtom *>
136-
(&(mol->GetAtom(i).GetScatteringPower()));
137-
scattpow[i].second=scattpow[i].first->GetAtomicNumber();
138-
}
139-
}
140-
for(unsigned int i=0;i<nb;++i)
141-
{
142-
if(scattpow[i].first==0) continue;
143-
const REAL x1=x(i),y1=y(i),z1=z(i);
144-
x += -x1;
145-
y += -y1;
146-
z += -z1;
147-
for(unsigned int j=i+1;j<nb;++j)
148-
{
149-
if(scattpow[j].first==0) continue;
150-
const REAL dist=sqrt(x(j)*x(j)+y(j)*y(j)+z(j)*z(j));
151-
//cout<<" -> d="<<dist<<"("<<radius(i)<<","<<radius(j)<<"):"<<scattpow[i].second<<","<<scattpow[j].second<<endl;
152-
if(dist<(1.10*(radius(i)+radius(j))))
153-
{
154-
if((1!=scattpow[i].second)||(1!=scattpow[j].second))
155-
{
156-
mol->AddBond(mol->GetAtom(i),mol->GetAtom(j),dist,.01,.02,false);
157-
}
158-
}
159-
}
160-
x += x1;
161-
y += y1;
162-
z += z1;
163-
}
164-
mol->BuildConnectivityTable();
165-
for(map<MolAtom*,set<MolAtom*> >::const_iterator pos=mol->GetConnectivityTable().begin();
166-
pos!=mol->GetConnectivityTable().end();++pos)
167-
{
168-
for(set<MolAtom*>::const_iterator pos1=pos->second.begin();
169-
pos1!=pos->second.end();++pos1)
170-
{
171-
for(set<MolAtom*>::const_iterator pos2=pos1;
172-
pos2!=pos->second.end();++pos2)
173-
{
174-
if(pos2==pos1) continue;
175-
if(mol->FindBondAngle(**pos1,*(pos->first),**pos2)== mol->GetBondAngleList().end())
176-
mol->AddBondAngle(**pos1,*(pos->first),**pos2,
177-
GetBondAngle(**pos1,*(pos->first),**pos2),0.01,0.02,false);
178-
}
179-
}
180-
}
181-
x0 /= nb;
182-
y0 /= nb;
183-
z0 /= nb;
184-
mol->GetCrystal().OrthonormalToFractionalCoords(x0,y0,z0);
185-
mol->SetX(x0);
186-
mol->SetY(y0);
187-
mol->SetZ(z0);
188-
mol->UpdateDisplay();
189-
VFN_DEBUG_EXIT("ZScatterer2Molecule()",6)
190-
return mol;
191-
}
19248

19349
////////////////////////////////////////////////////////////////////////
19450
//

ObjCryst/wxCryst/wxZScatterer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
#include "ObjCryst/wxCryst/wxScatterer.h"
2424
#include "ObjCryst/ObjCryst/ZScatterer.h"
25+
#include "ObjCryst/ObjCryst/Molecule.h"
2526

2627
namespace ObjCryst
2728
{

0 commit comments

Comments
 (0)