gen_ner

482 views
Skip to first unread message

chao zhou

unread,
Jul 4, 2022, 12:11:47 AM7/4/22
to Vampire Users
Hi
I RUN the code ,but it reprot error as follow
Traceback (most recent call last):
  File "/data/home/js_lili/zc/MnB2/AlB2/gen_nbrs_example.py", line 103, in <module>
    nbrs_all = vstack( ( nbrs_1, nbrs_2) )
  File "<__array_function__ internals>", line 180, in vstack
  File "/data/home/js_lili/.conda/envs/js_lili/lib/python3.9/site-packages/numpy/core/shape_base.py", line 282, in vstack
    return _nx.concatenate(arrs, 0)
  File "<__array_function__ internals>", line 180, in concatenate
ValueError: all the input array dimensions for the concatenation axis must match exactly, but along dimension 1, the array at index 0 has size 6 and the array at index 1 has size 0

and I run the example  it only output interaciton,how to print the atom_id and lattice vector ,and the interaction is isotropical?
gen_nbrs_example.py

gabo...@gmail.com

unread,
Jul 4, 2022, 7:12:35 PM7/4/22
to Vampire Users
How to print the unit cell lattice vectors? Regarding that question in your previous post below, you should be able to use the savetxt function [1-3] of numpy [4].  In the attached screenshot (gen_nbrs_example-m.png), you can see that I took the gen_nbrs_example-m.py from [5] and modified it to print the "Unit cell vectors" that are set within gen_nbrs_example-m.py using multiple savetxt functions:

text=["\n# Unit cell vectors: "]
savetxt(f,text,fmt="%s")
savetxt(f,ua, fmt="%1.1f", newline="\t")
text=["\r"]
savetxt(f,text,fmt="%s")
savetxt(f,ub, fmt="%1.1f", newline="\t")
text=["\r"]
savetxt(f,text,fmt="%s")
savetxt(f,uc, fmt="%1.1f", newline="\t")

An alternative to savetxt is the print function [6].  See create-ucf.py at [7] for an example that uses a Python print function.

As you can see in the screenshot, values for id, cx, cy, cz, mat, lc, hc, interactions n, and exctype that are needed for a ucf file are missing and not yet written in the outputted interactions_ucf.txt. 

Feel free to use the above savetxt example as a guide so that you can further program the Python script to output those quantities.

Regarding the ValueError, I'm not able to follow the changes you made to the original gen_nbrs_example-m.py script, but the changes seem to be the cause of what broke the script (e.g., the gen_nbrs_example.py that you previously attached).


Kind Regards,
Gavin
VAMPIRE user
gen_nbrs_example-m.py
gen_nbrs_example-m.png
Message has been deleted

chao zhou

unread,
Jul 4, 2022, 9:58:52 PM7/4/22
to Vampire Users
Hi, Gavin 
Thank you for your help,It is true that the lattice vector is printed, but it seems that the occupation of atoms is not written.Then I still report an error according to your script. Is the distance of the exchange action I defined wrong? I established the cell and considered the two interactions and the approximate distance, but I still report an error?
thank you for your help.
ValueError: all the input array dimensions for the concatenation axis must match exactly, but along dimension 1, the array at index 0 has size 6 and the array at index 1 has size 0

gen_nbrs_example-m.py

gabo...@gmail.com

unread,
Jul 5, 2022, 1:44:47 AM7/5/22
to Vampire Users
As seen in the attached screenshot (ucf_gen_nbrs.png), I have modified gen_nbrs_example-m.py and renamed it "ucf_gen_nbrs.py" and also changed the outputted filename from "interactions_ucf.txt" to "my_file.ucf".  You should also see that it now outputs the occupation of atoms information (id, cx, cy, cz, mat, lc, and hc), which can be changed by editing ucf_gen_nbrs.py

As seen in the attached ValueError.png, I added a print(size(nbrs_2)) to it for debugging and your error seems to be caused by the nbrs_2 array being empty.

Since I didn't write the original gen_nbrs_example-m.py script, I'm guessing nbrs_2 is a list of next nearest neighbors.  To resolve that error, you probably have to adjust dist_max, dist_1, dist_2, and/or dist_err to fill the nbrs_2 array. 

Also, feel free to improve the script and correct any errors in the coding or comments that I added should you find any.

Kind Regards,
Gavin
VAMPIRE user

ucf_gen_nbrs.py
ValueError.png
ucf_gen_nbrs.png

chao zhou

unread,
Jul 10, 2022, 11:09:10 PM7/10/22
to Vampire Users
Thanks  Gavin
Thank you very much for your script support, but due to the problem of my lattice definition, it is strange that I am a hexagonal lattice, expanded the  orthogonal lattice with (1 -1 0 1 1 0 0 0 1) , but it still reports an error.
Traceback (most recent call last):
  File "/data/home/js_lili/zc/MnB2/0GPa-2/ucf_gen_nbrs.py", line 93, in <module>
    atomic_positions = array([int(atom_id[i]),x[i],y[i],z[i],mat[i],lc[i],hc[i]],dtype=object)
IndexError: index 2 is out of bounds for axis 0 with size 2

ucf_gen_nbrs.py

gabo...@gmail.com

unread,
Jul 11, 2022, 12:45:43 AM7/11/22
to Vampire Users
It looks like you added two additional atoms positions of

2       0.5     0.5     0.5
3       0       0       0.5

When you did that, it looks like you forgot to change the arrays for mat, lc, and hc:

# mat, lc, and hc
mat = array([0,0],dtype=int)
lc = array([0,0],dtype=int)
hc = array([0,0],dtype=int)

To remove the error, you would need to add two additional mat, lc, and hc values to the arrays:

# mat, lc, and hc
mat = array([0,0,0,0],dtype=int)
lc = array([0,0,0,0],dtype=int)
hc = array([0,0,0,0],dtype=int)

The script as is will output all mat, lc, and hc values as 0 by default, and the script is not able set the proper values for those.  So you have to manually change those either in the arrays above in the script or in the outputted file (my_file.ucf) to appropriate values for your simulation.

Kind Regards,
Gavin
VAMPIRE user

chao zhou

unread,
Jul 12, 2022, 5:05:10 AM7/12/22
to Vampire Users
Thanks Gavin, if more exchange interaction are considered, how to adjust it with the script. very thanks to your help. 
and another question is I  see the BUG with TB2J .
  Bug fix: convention in Vampire output (tensor->tensorial, and a factor of 2 added to the exchange values)
If in the format of tensorial , there is a facotor 2 ? Then Isotropic without the factor of 2?

gabo...@gmail.com

unread,
Jul 13, 2022, 12:45:47 AM7/13/22
to Vampire Users
Thanks Gavin, if more exchange interaction are considered, how to adjust it with the script. very thanks to your help. 

The number of exchange interactions can be changed by adjusting the ranges of the for loops in ucf_gen_nbrs.py.  You can change the [-1,0,1] arrays or/and you can change values 13 and 14 depending on what you need.

for z_i in [-1,0,1]:
    for y_i in [-1,0,1]:
        for x_i in [-1,0,1]:
...
            atom_id_dup = append(atom_id_dup,atom_id)
...
for i in range(13*n,14*n):
    for j in range(len(atom_id_dup)):

and another question is I  see the BUG with TB2J .
  Bug fix: convention in Vampire output (tensor->tensorial, and a factor of 2 added to the exchange values)
If in the format of tensorial , there is a facotor 2 ? Then Isotropic without the factor of 2?
 
The ucf file outputted by the latest version of TB2J should already be in the correct format for input into VAMPIRE.

In the source code file io_vampire.py [1] of the current 0.7.3.rc1 version of TB2J, you should see the factor of 2 on line 54

myfile.write(f"{Jtensor[i,j]*2.0/J} ")

In an older version of TB2J, they are saying there was a bug were the source code was incorrect as it was missing the factor of 2, such the TB2J outputted the tensorial values a factor of 2 smaller than they should have been.  To simply for comparison, the same source code line but with the 2.0 missing would be:

myfile.write(f"{Jtensor[i,j]/J} ")

However, the actual changes between the old and new TBJ2 code is more complicated then that.  In the old 0.3.1 version of TB2J, you should see on line 63 of io_vampire.py [2] that instead of Jtensor[i,j]/J it had:

Jij=val / J

chao zhou

unread,
Jul 19, 2022, 10:13:25 AM7/19/22
to Vampire Users
Thanks  Gavin. Often  with the distance I set , no more interaction was produced if i change the range of x,y,z_i. The x,y,z_i may define the direction of the exchange , is it right? But what does the 13 , 14 mean?  If more interaction produce ,Will it affect the simulation , because these functions are equivalent.And finally, my question is actually how to add a third nearest neighbor. Thanks for your help.
Zhou Chao
.

gabo...@gmail.com

unread,
Jul 19, 2022, 11:38:15 PM7/19/22
to Vampire Users
Thanks  Gavin. Often  with the distance I set , no more interaction was produced if i change the range of x,y,z_i. The x,y,z_i may define the direction of the exchange , is it right?

Controlling dist_max, dist_1, dist_2, and/or dist_err to capture different sets of atoms in the cell is another way to change the number of interactions in the exchange list, but typically one would set those to capture just the 1st and 2nd nearest neighbors.

That x,y,z_i part of the code was written by Miftah [1].  The comment that Miftah has in the code for it is:

#duplicate for generating neighbour cells

If I understand that comment correctly, the "for x_i in [-1,0,1]" for example will create a duplicate of the unit cell in both the -x and +x direction.  So if you need more atoms in your exchange list from a larger supercell, I'm thinking you can adjust that to have as many duplicates of the unit cell in the x direction that you want.
 
But what does the 13 , 14 mean?

The comment by Miftah on that is:

#center cell is #14 in range 13*n:14*n

If interpret that correctly, the 14 selected the center cell as the reference cell in Miftah 's original Python code which was modified with a fix by the user qq970 for a cubic unit cell [2].  So if you select a cell that is on the edge in the x direction, I would expect the exchange list to be smaller as you would not have cells with neighboring atoms in the x direction.  On the other hand, if you put the reference cell (from which you specify your nearest neighbor distances from) in the center, you may have neighboring cells with atoms in all directions.

  If more interaction produce ,Will it affect the simulation , because these functions are equivalent.

Not sure, but if you run the simulations with a different number of interactions and check what it gives you then your analysis of the results of the simulations should give you the answer.

And finally, my question is actually how to add a third nearest neighbor. Thanks for your help.

It looks like the second nearest neighbors have dist_2, J_2, and nbrs_2 variables as well as an elif statement in the Python file.

So, most likely the third nearest neighbors would needed to have dist_3, J_3, and nbrs_3 variables as well as a corresponding elif statement, which you could edit the Python file to have.


Hopefully that helps and kind regards,
Gavin
VAMPIRE user

chao zhou

unread,
Jul 27, 2022, 11:15:41 AM7/27/22
to Vampire Users
Thanks Gavin, but i set it as you recommend , it did not generate the nerb_3, could you give some advice ? the size(nerb_3) is not 0..
Zhou Chao

ucf_gen_nbrs.py

gabo...@gmail.com

unread,
Jul 28, 2022, 12:18:37 AM7/28/22
to Vampire Users
It looks like you forgot to put nbrs_3 so that it is included in what is written to the output.  Try the attached file.

In your file, you had the line:

nbrs_all = vstack( ( nbrs_1, nbrs_2) )

In the attached file, you should see that it was changed to:

nbrs_all = vstack( ( nbrs_1, nbrs_2, nbrs_3) )

Kind Regards,
Gavin
VAMPIRE user

ucf_gen_nbrs.py
Reply all
Reply to author
Forward
0 new messages