Slookeur / Atomes

atomes: codeblocks dev files
GNU Affero General Public License v3.0
8 stars 1 forks source link

A confusing problem when opening *.XYZ file #13

Closed sailangyf closed 2 years ago

sailangyf commented 2 years ago

Dear Dr. Sébastien Le Roux There is a confusing problem when I used Atomes. I have a *.XYZ file which has been attached (You need to change hh.txt to hh.XYZ, because I couldn't upload an XYZ file here). I could open it by Atomes in my Ubuntu 20.04, however, I couldn't import the file by Windows Atomes. hh.txt

Slookeur commented 2 years ago

Hello, I see that your file contains a lot information on the comment (2nd) line, I will try it on Windows and let you know what happen, but you might want to give it a try without all this information and simply let a blank line:

13500

Si 2.552920137 41.8169424062 1.9318941544

Ok, this has nothing to do with the comment line, for some reasons Linux and Windows do not see the same number of lines in your file, I would need time to figure out why and if there is a fix for that. Linux finds 135020 lines (the good number) and Windows only 135019, my guess is that there is an end of line symbol missing somewhere, windows likely being sensitive to that, the point being to find where in your 135019-20 lines long file ...

sailangyf commented 2 years ago

Thank you for your reply! I really appreciate your clear explanation. It's really confusing. I could open the file by using OVITO, VESTA, and VMD in Windows.

Slookeur commented 2 years ago

To be honest, when I will find where the problem is, and what it is exactly I will try to understand why Windows is that sensitive to it, and try to correct the code accordingly. I will let you know here when this is done.

sailangyf commented 2 years ago

Thank you very much!

Slookeur commented 2 years ago

Ok, found few things, the issue comes from the windows version of the fread function, a standard C function that I use for reading the coordinates file. For some reason it detect way to many End Of Line symbols in your file, precisely 255 in excess ... no issue when using the fgets function ... fread is used in the case of OpenMP read (so far enabled by default) so I turned OpenMP off and it works (with fgets), I will see if I can find some info about this.

In the mean time I tested a modified version of your file using:

cut -c 1-38 hh.xyz > test.xyz

To try to produce a file with clean EOL just keep the last 38 characters on each line, then it works just fine with the OpenMP read (fread) so my final interpretation is that the issue comes from a mixed combination of the file prepared with a tool that insert hidden characters that mess with the 'fread' function on windows, and, a possible lack of protection of the read on the programming side to get rid of those hidden characters.

I must confess that the appropriate fix, to ensure that fread is behaving properly on windows might take some time, in the mean time your options are either:

sailangyf commented 2 years ago

Thank you very much for devoting to solving the problem! Now the confusing point is clear! Actually, I prepared the hh.xyz by OVITO which originally was a lammpstrij file from LAMMPS. I also directly fabricated the XYZ file in LAMMPS and it could be imported to ATOMES in windows. I will pay attention to the methods I use to prepare the *.XYZ file! Thank you again for developing the excellent software! (I have starred it in Github! : ) ) Looking forward to this software getting better and better.

Slookeur commented 2 years ago

Thanks ;-) So more details today: your XYZ file contains mixed EOL (End of Line Terminators) (CRLF symbols from the windows world) and (LF symbols from the Unix world) and Windows cannot handle this, I found a way to handle this issue in Atomes, so that you should not have to care about how you create your files, however I am not sure that the modification is appropriate so I will ask for advise before modifying the code for a new release.

sailangyf commented 2 years ago

It sounds great! Looking forward to it! : )

Slookeur commented 2 years ago

Ok, problem solved, a new release will be proposed when possible. New release is now on line.