Probe-Particle / ppafm

Classical force field model for simulating atomic force microscopy images.
MIT License
49 stars 18 forks source link

CoPc-IETS example corrupted #71

Closed ondrejkrejci closed 8 months ago

ondrejkrejci commented 1 year ago

https://github.com/Probe-Particle/ppafm/tree/main/examples/CoPc-IETS error:

./run.sh: line 4: 484062 Segmentation fault      python3 ../../relaxed_scan.py --vib 3
ELpolloGUAPO commented 1 year ago

Hello, When it would be possible to fix this? I am learning to use this program and this is exactly the type of system I want to simulate.

ondrejkrejci commented 1 year ago

Hello @ELpolloGUAPO , sorry for my late reply. For now just a quick answer - the issue lies in the IETS technique (rarely used for now), which is connected with nc-AFM (and STM), but not with the molecule as such and nc-AFM is running for that just fine.

To run this without after installation and get frequency shift images, you can just do:

ppafm-generate-ljff
ppafm-relaxed-scan
ppafm-plot-results --df

which will create a folder with df images in the example folder.

You can also use ppafm-gui if you can install the opencl-version of the code

Just a quick add, to get a better agreement between theory and experiment, you should calculate the electrostatic force-field around your molecule and add it to your simulations. The truth is that we do not have any good tutorial for this. Let us know if you need more support.

ondrejkrejci commented 10 months ago

@ProkopHapala, sorry to bother you - just an interesting observation, while checking the current version of PPSTM, I have find out, that the eigenvector procedure is working there fine for FePc_Au example. The overall IETS test is not working, but it calculates the eigenvectors well and store them in an npz file. Thus I am wondering, what can be the problem, that CoPc, which is just free in vaccum has problems and FePc that is flatter and has the extra layer bellow is working fine.

ProkopHapala commented 10 months ago

@ProkopHapala, sorry to bother you - just an interesting observation, while checking the current version of PPSTM, I have find out, that the eigenvector procedure is working there fine for FePc_Au example. The overall IETS test is not working, but it calculates the eigenvectors well and store them in an npz file. Thus I am wondering, what can be the problem, that CoPc, which is just free in vaccum has problems and FePc that is flatter and has the extra layer bellow is working fine.

Aha, interesting, Thanks!. Do you think it is something connected just with the stroring / loading the data (not with the actuall calculation ?)

ondrejkrejci commented 9 months ago

@ProkopHapala - I have went to it for a little while and it seems that the problem is somewhere with wrong memory assignment;

The problem is on this line: https://github.com/Probe-Particle/ppafm/blob/a1a7a72ff184a531f687b1f97e947bd75cf6dd78/ppafm/cpp/ProbeParticle.cpp#L627 And if my printf is really following the mistake in the exact spot, then problematic should be already the second step at that line: getPPforce( rTip, rPP, f1 ); which sounds strange to me - why it is sometimes working and sometimes not. I am leaving it for now and will work on other things.

ondrejkrejci commented 9 months ago

Maybe you can wait for #237 to be merged, so the ppafm/cli/plot_results.py is working correctly.

ProkopHapala commented 9 months ago

@ProkopHapala - I have went to it for a little while and it seems that the problem is somewhere with wrong memory assignment; https://github.com/Probe-Particle/ppafm/blob/a1a7a72ff184a531f687b1f97e947bd75cf6dd78/ppafm/cpp/ProbeParticle.cpp#L627 And if my printf is really following the mistake in the exact spot, then problematic should be already the second step at that line: getPPforce( rTip, rPP, f1 ); which sounds strange to me - why it is sometimes working and sometimes not.

Yes, as I wrote in the email. According tests I did in new debug_IETS branch the problem is that gridF pointer seems invalid at the time wehn we call stiffnessMatrix() so getPPforce() tries to read from invalid memory address and cause segfault. I can reproduce the error just by reading Vec3d gf=gridF[0]; at the begining of stiffnessMatrix() as you can as on this line

I guess the origin of this problem is that Garbage Collector in python deallocate numpy array to which we store the pointer in gridF, because it concludes it is now longer needed. Perhaps we can resolve it if we keep the variable storing the numpy array in proper scope (in Python) - but not sure, need to look on it deeper.