What Does the coordinate list next to the cartesian coordinates of an atom represent in neighbor_list - pymatgen

I was trying to analyze the result obtained by using pymatgen.analysis.local_env module by using min_dist approach by using following script:
from pymatgen.analysis.local_env import
structure_from_cif = Structure.from_file("mp-685151TiO.cif")
neighbor_list = []
for i in range(len(structure_from_cif.species)):
neighbors = get_neighbors_of_site_with_index(structure_from_cif, i, approach = "min_dist", delta = 0.3, cutoff= 3)
neighbor_list.append([str(structure_from_cif.species[i])+str(i), str(neighbors)])
I get the following output a part of which is shown below. I understand that the first coordinates in () are the Cartesian coordinates. I thought the coordinates in [] are of periodic image but I am in doubt when I analyze them. Could any one please help me to understand the actual meaning and significance of those coordinates in [], for example
[-0.3863, -0.2759, 1.3863] in first case and so on.
['Ti0',
'[PeriodicSite: O (-0.8310, -0.7224, 22.9070) [-0.3863, -0.2759, 1.3863], PeriodicSite: O (-1.3193, 1.8955, 23.8405) [-0.3863, 0.7241, 0.3863], PeriodicSite: O (1.6691, -0.7224, 24.2132) [0.6137, -0.2759, 1.3863], PeriodicSite: O (1.1809, 1.8955, 25.1466) [0.6137, 0.7241, 0.3863]]'],
['Ti1',
'[PeriodicSite: O (-1.3145, -0.7079, 26.8777) [-0.5786, -0.2704, 1.5786], PeriodicSite: O (-1.8028, 1.9100, 27.8111) [-0.5786, 0.7296, 0.5786], PeriodicSite: O (1.1856, -0.7079, 28.1838) [0.4214, -0.2704, 1.5786], PeriodicSite: O (0.6974, 1.9100, 29.1173) [0.4214, 0.7296, 0.5786], PeriodicSite: O (-1.0443, -0.0383, 29.4055) [-0.4205, -0.0146, 1.4205]]'],
['Ti2',
'[PeriodicSite: O (-1.4562, 0.0380, 33.2391) [-0.5796, 0.0145, 1.5796], PeriodicSite: O (-1.9444, 2.6559, 34.1725) [-0.5796, 1.0145, 0.5796], PeriodicSite: O (1.0440, 0.0380, 34.5452) [0.4204, 0.0145, 1.5796], PeriodicSite: O (0.5557, 2.6559, 35.4787) [0.4204, 1.0145, 0.5796], PeriodicSite: O (-1.1854, 0.7081, 35.7657) [-0.4213, 0.2705, 1.4213]]'],

The second set of co-ordinates in square brackets are the fractional co-ordinates of that site with respect to the Structure's Lattice. Fractional co-ordinates wrap around periodic boundaries, so:
[-0.3863, -0.2759, 1.3863]
is equivalent to these co-ordinates in the [0,1) range:
[0.6137, 0.7241, 0.3863]
For technical reasons, fractional co-ordinates are not wrapped to [0, 1) by default however, since this information is meaningful for some simulation code. For practical purposes however, the easiest way to interpret them is in the [0, 1) range.

Related

Sympy - Simplify expression within domain

Can Sympy automatically simplify an expression that includes terms like this one:
cos(x)/(cos(x)**2)**(1/2)
which can be simplified to 1 in the domain that I am interested in 0 <= x <= pi/2 ?
(Examples of other terms that could be simplified in that domain: acos(cos(x)); sqrt(sin(x)**2); sqrt(cos(2*x) + 1); etc.)
If you know the functions that are in your expression (such as sin, cos and tan), you can do the following according to this stack overflow question:
from sympy import *
x = symbols("x", positive=True)
ex = cos(x)/(cos(x)**2)**(S(1)/2)
ex = refine(ex, Q.positive(sin(x)))
ex = refine(ex, Q.positive(cos(x)))
ex = refine(ex, Q.positive(tan(x)))
print(ex)
Note that Q.positive(x*(pi/2-x)) did not help in the process of simplification for trig functions even though this is exactly what you want in general.
But what if you might have crazy functions like polygamma? The following works for some arbitrary choices for ex according to my understanding.
It wouldn't be a problem if the expression was already generated before by SymPy, but if you are inputting the expression manually, I suggest using S(1)/2 or Rational(1, 2) to describe one half.
from sympy import *
# define everything as it would have come from previous code
# also define another variable y to be positive
x, y = symbols("x y", positive=True)
ex = cos(x)/(cos(x)**2)**(S(1)/2)
# If you can, always try to use S(1) or Rational(1, 2)
# if you are defining fractions.
# If it's already a pre-calculated variable in sympy,
# it will already understand it as a half, and you
# wouldn't have any problems.
# ex = cos(x)/(cos(x)**2)**(S(1)/2)
# if x = arctan(y) and both are positive,
# then we have implicitly that 0 < x < pi/2
ex = simplify(ex.replace(x, atan(y)))
# revert back to old variable x if x is still present
ex = simplify(ex.replace(y, tan(x)))
print(ex)
This trick can also be used to define other ranges. For example, if you wanted 1 < x, then you could have x = exp(y) where y = Symbol("y", positive=True).
I think subs() will also work instead of replace() but I just like to be forceful with substitutions, since SymPy can sometimes ignore the subs() command for some variable types like lists and stuff.
You can substitute for a symbol that has the assumptions you want:
In [27]: e = cos(x)/(cos(x)**2)**(S(1)/2) + cos(x)
In [28]: e
Out[28]:
cos(x)
cos(x) + ────────────
_________
╱ 2
╲╱ cos (x)
In [29]: cosx = Dummy('cosx', positive=True)
In [30]: e.subs(cos(x), cosx).subs(cosx, cos(x))
Out[30]: cos(x) + 1

Using custom QItemDelegate with a QSortFilterProxyModel

I have a custom QSortFilterProxyModel to only show certain rows and columns in a table. I also have a custom QItemDelegate to control how certain values in the table are drawn. I'm only applying the delegate to the columns that need it and the problem seems to be that when I have the proxy model hide certain columns it messes up the delegate.
For example, suppose I have columns A-G and I apply my custom delegate to column F.
A B C D E F G
-------------------
o o o o o X o
o o o o o X o
o o o o o X o
If my proxy model doesn't show column B, my delegate ends up getting applied to column G instead.
A C D E F G
----------------
o o o o o X
o o o o o X
o o o o o X
I've been able to work around the problem by hiding the columns on the view instead of in the proxy model by calling
table->setColumnHidden(B, true);
And I suppose that works, but is that the only solution? It seems like bug that the delegate and proxy model classes don't work better together, like you can use one or the other but not both on the same model very well.
You may try mapToSource on filtered indices (one per column) and check the original column and set the corresponding item delegate based on it.
for (int i = 0; i < proxy->columnCount(); ++i) {
if (proxy->mapToSource(proxy->index(0, i)).column() == 6) {
table->setItemDelegateForColumn(i, yourDelegate);
}
}
This is one of many good reasons not to use column position detection in display delegates. If you let users re-arrange columns in the view, that also is a problem. I don't think it's a bug, but I HAVE wished in the past that there was a way to assign a default delegate at the item model level. Perhaps as a Role or something.
Anyway, one simple workaround, if you have control of the data, is to store the column/field ID right in the data itself, as a custom data role, e.g. modelIndex.setData(FIELD_ONE, Qt::UserRole + 1) (where FIELD_ONE is some enum of your columns, for example). Then the delegate can just check that role and know what to do.

How to represent a data structure like this in python pandas?

Somehow I can't figure out what would be the best/most convenient representation of my data in python pandas.
In principle the data is structured like this:
| Group1 | | Group2 | ...
x y z prop1 prop2 prop3 prop1 prop2 prop3
0 o o o o o o o o o
1 o o o o o o o o o
2 o o o o o o o o o
.
.
.
So to say, I have a fixed number of rows indexed by 0, 1, 2, ... Each row has fixed (x,y,z) coordinates and a fixed number of data groups (here: Group1, Group2, ...) which themselves have a fixed number of properties. The "o"s denote data values. What I would want is a DataFrame where I could write
import pandas as pd
df = pd.Dataframe( "the_unknown_code" )
df['x'] # giving the "x"-column
df['Group1']['prop1'] # giving the "prop1"-column of "Group1"
This would be easy from my point of view, if DataFrame-columns could be DataFrames again, which does not seem to be possible. I tried to get along with Panel and Multiindex, but it seemed that I would have duplicate data or too complex indexing. I would highly appreciate any hints.
df = pd.DataFrame(np.arange(27).reshape(3,9) ,
columns = [
['x' , 'y' , 'z' , 'Group1' , 'Group1' , 'Group1' , 'Group2' , 'Group2' , 'Group2'] ,
[ 'x' , 'y' , 'z' , 'prop1' , 'prop2' , 'prop3' , 'prop1' , 'prop2' , 'prop3']
]
)
df['Group1']['prop1']
# 0 3
# 1 12
# 2 21

Minimal transversal of a Hypergraph

Hi This is my first post, so please go easy on me. I tried going through an algorithm Dualize and Advance for generating maximal frequent item sets. I considered an example as follows
Transactions
abcde
ace
bd
abc
and minimum frequency threshold as 2.
Now, I have a problem understanding how to generate 'minimal transversals' part of the algorithm.
I know that transversal is a subset of vertices of the hypergraph that intersects every hyper edge. So the initial set of minimal transversals should be {a,b,c,d,e} if I am not wrong.
Can you please explain me this part of 'minimal transversal' w.r.t the transactions.
Ok, I ll try to answer my question.
At the end of first iteration of the algorithm and for the given transactions, {abc} is emanated as maximal frequent itemset. Here is how I understood,
minimal transversal X = S1' = {a,b,c,d,e}
S2 = {abc} is maximal and S2' = {de}
Find minimal transversal of S2' which is {d,e}
Now, X = {d,e}, consider 'd' ,
S3 = {bd} is maximal and S3' = {ace}
Now, consider 'e'
S4 = {ace} is maximal and meanwhile I get {ad} , {be} ,{cd} and {de} as minimal transversals which are infrequent.
A subset T of V is a transversal (or hitting set) of H if it
intersects all the hyperedges of H,
'minimal transversal' -> the smallest possible set that we get.
Also, we enforce ordering in our algorithm a>b>c>d>e
Iteration 1:
S1 = {}
S1' = {abcde}
Tr = {a,b,c,d,e} [All nodes are required to cut Si']
Iteration 2:
S2 = {abc}
S2' = {de}
Tr = {d,e} [Two nodes are required to cut Si']
Iteration 3:
S3 = {abc, bd}
S3' = {de, ace}
Tr = {e, cd, ad} [Three nodes are required to cut Si']
Iteration 4:
S4 = {abc, bd, ace}
S4' = {de, bd, ace}
Tr = {de, cd, ad, be} [Four nodes are required to cut Si']
All minimal transversals Tr are infrequent so the algorithm ends.

Prolog If Then Else fail with member predicate

Hello guys I am working on a prolog game and I need to write a piece of code that will:
Take a number (ArmyNo) from the user.
Take an X coordinate
Take an Y coordinate.
Then I have a list that is named TempBoard and it looks like this:
([
(1,1,-,-),(1,2,-,-),(1,3,-,-),(1,4,-,-),
(2,1,-,-),(2,2,-,-),(2,3,-,-),(2,4,-,-),
(3,1,-,-),(3,2,-,-),(3,3,-,-),(3,4,-,-),
(4,1,-,-),(4,2,-,-),(4,3,-,-),(4,4,-,-)
]).
before I add this (X,Y,w,ArmyNO) to the list I first want to check it if it is already there.
I attempted to do that by using this code but it does not seem to work properly:
%#######Got the number####
repeat,
%Get Cordinates X & Y.
writelist( [TempBoard,'select coordinates for the horizontal axis 1 to 4 to place your soldier Mr. Human',nl]),
read(X),
writelist(['select coordinates for the vertical axis 1 to 4 to place your soldier Mr. Human',nl]),
read(Y),
%Check if they are in the list.
(
member( (X,Y,w,ArmyNo),TempBoard ) ->
( replace((X,Y,w,ArmyNo),TempBoard,NewBoard) ) ;
(
writelist(['selected positions are not available in the table Mr.Human',nl]) , fail
)
).
%%
(X, Y, w, ArmyNo)
cannot be unified with any member of your example list because w doesn't unify with -. You may have meant W.