vincefn / objcryst

Free Objects for Crystallography : Fox / ObjCryst++
Other
23 stars 10 forks source link

Obtaining a PXRD pattern for multiple structures with --cif2pattern #47

Closed fxcoudert closed 4 years ago

fxcoudert commented 4 years ago

So, not sure if this is an actual issue, but the mailing list over on sourceforge seems inactive, so I am writing here.

I am trying to use FOX to calculate X-ray diffraction patterns for models of amorphous solids (from molecular simulation). This is on microscopic models of amorphous phases, so what I am doing is:

The system I am working with currently has ~2000 atoms, with units cells of ~35 Å in size. Each FOX calculation takes about 2 minutes, so the complete process is quite slow.

What I am wondering is: how much of that time is due to the actual calculation, and how much is due to the set up and could probably be eliminated if I could run a single FOX calculation with all my inputs. Is that possible? Any advice would be welcome.

vincefn commented 4 years ago

That sounds awfully slow, would you care to share an example CIF (and the command-lline used) for this ? I'll try to take a look. The cif2pattern was only meant for a single pattern generation, unfortunately. You could change the c++ code to handle multiple inputs, look at the code in Fox.cpp, and the standalone examples in ObjCryst/example

Ultimately it should be much easier to do this using the python interface in pyobjcryst, and customise what is calculated. This is not yet easily (pip or conda) installable yet (it's being merged in the main diffpy repositories), but if you feel up to it (depends if you program in python), you can try my libobjcryst and pyobjcryst repositories.

fxcoudert commented 4 years ago

Example CIF file is here: https://gist.github.com/fxcoudert/cc6fdcb38e906ecb936d1c94e5d6293e The command I run is:

Fox-nogui --silent toto.cif --cif2pattern 0.4246 10.0 1000 0.001 toto

The output says:

Merging ScatteringPower: Zn[Zn] (95 identical scattering powers)
Merging ScatteringPower: H1[H1] (575 identical scattering powers)
Merging ScatteringPower: H2[H2] (383 identical scattering powers)
Merging ScatteringPower: C1[C1] (383 identical scattering powers)
Merging ScatteringPower: C2[C2] (191 identical scattering powers)
Merging ScatteringPower: C3[C3] (191 identical scattering powers)
Merging ScatteringPower: N[N] (383 identical scattering powers)
ConnectAtoms: found Molecule: C1384 C2192 C3192 H1574 H2384 N384 Zn96
Changed powder pattern: 1000 points, 2theta=  0.000 ->   9.990, step= 0.010
Auto-simulating powder pattern:(0)
   Crystal #0: 
   Wavelength: 0.4246
   2theta: 0->10?(1000 points)
   peak width: 0.001?
   to FILE:tutu_0.dat

and the “wait” is between the last Merging ScatteringPower line and the ConnectAtoms: found Molecule line.

vincefn commented 4 years ago

and the “wait” is between the last Merging ScatteringPower line and the ConnectAtoms: found Molecule line.

OK, that makes sense: when importing a CIF the program will try to connect all the atoms (find molecules or polyhedra), which can take a while if the connectivity is complicated.

As you have compiled Fox from source, I would just advise you to find the line in Fox.cpp: bool oneScatteringPowerPerElement=true, connectAtoms=true; and change to: bool oneScatteringPowerPerElement=true, connectAtoms=false;

with that it should be much faster

fxcoudert commented 4 years ago

find the line in Fox.cpp

That makes sense, because connectivity is probably not useful when calculating a PXRD pattern. Could you possibly consider making it a default if --cif2pattern is passed?

Another (very minor) thing I noticed: --silent is apparently not, well, very silent. It still outputs one line per atom found in the CIF file (Creating new scattering power for:H), which seems weird for a silent mode.

vincefn commented 4 years ago

Yes, the silent options mutes the main global optimisation output (very lengthy), but not yet the cif outputs. I'll make the connectAtoms=false the default with cif2pattern

Is the speed OK now ?

fxcoudert commented 4 years ago

Is the speed OK now ?

I think so, it's taking about 1 second per structure. Thank you so much for the quick responses!

Another question: what would it take to calculate other properties, such as a neutron structure factor F(Q)?

vincefn commented 4 years ago

You can calculate the neutron powder pattern using --cif2patternN For other calculations and output you have to modify the code around lines 1100-1150 in Fox.cpp

vincefn commented 4 years ago

Fixed in 841cb05f0587