When I read ".mol" file and convert to Smiles using Rdkit, the smiles comes with H, However 'H' are not present in the original .xyz file. Here is the way I did:
m3 = Chem.MolFromMolFile('Al_neutral.mol', strictParsing=False)
ms = Chem.MolToSmiles(m3)
mol = Chem.MolFromSmiles(ms)
When I print 'ms' it is
'[Al]12[AlH2]34[Al]5[AlH2]16[Al]1[AlH2]57[Al]5[AlH2]89[Al]3[AlH2]23[Al]8[AlH2]15[Al]46379'
Why 'H' are there and how can we interpret these numbers? Please advise me. Thanks in advance.
The hydrogens you see in the SMILES are modelled implicitly. Take a look at this blog post for information about implicit and explicit hydrogens. You will notice that if you convert back to a ".mol" representation the hydrogens will not be present:
smiles = '[Al]12[AlH2]34[Al]5[AlH2]16[Al]1[AlH2]57[Al]5[AlH2]89[Al]3[AlH2]23[Al]8[AlH2]15[Al]46379'
mol = Chem.MolFromSmiles(smiles)
print(Chem.MolToMolBlock(mol))
RDKit 2D
13 24 0 0 0 0 0 0 0 0999 V2000
1.0607 0.0000 0.0000 Al 0 0 0 0 0 3 0 0 0 0 0 0
-0.0000 -1.0607 0.0000 Al 0 0 0 0 0 6 0 0 0 0 0 0
-1.0607 0.0000 0.0000 Al 0 0 0 0 0 3 0 0 0 0 0 0
0.0000 1.0607 0.0000 Al 0 0 0 0 0 6 0 0 0 0 0 0
-1.4230 1.5350 0.0000 Al 0 0 0 0 0 3 0 0 0 0 0 0
-2.1213 -1.0607 0.0000 Al 0 0 0 0 0 6 0 0 0 0 0 0
-2.9642 0.1801 0.0000 Al 0 0 0 0 0 3 0 0 0 0 0 0
2.1213 -3.1820 0.0000 Al 0 0 0 0 0 6 0 0 0 0 0 0
1.0607 -2.1213 0.0000 Al 0 0 0 0 0 3 0 0 0 0 0 0
2.1213 -1.0607 0.0000 Al 0 0 0 0 0 6 0 0 0 0 0 0
3.1820 -2.1213 0.0000 Al 0 0 0 0 0 3 0 0 0 0 0 0
-1.8974 0.1120 0.0000 Al 0 0 0 0 0 6 0 0 0 0 0 0
-1.0607 -2.1213 0.0000 Al 0 0 0 0 0 6 0 0 0 0 0 0
1 2 1 0
2 3 1 0
3 4 1 0
4 5 1 0
5 6 1 0
6 7 1 0
7 8 1 0
8 9 1 0
9 10 1 0
10 11 1 0
11 12 1 0
12 13 1 0
4 1 1 0
12 5 1 0
10 1 1 0
9 2 1 0
13 10 1 0
13 2 1 0
6 3 1 0
12 7 1 0
13 4 1 0
13 6 1 0
11 8 1 0
13 8 1 0
M END
Related
I have an column vector with following format in R: num [1:2464, 1].
I want to diagonal the vector, so each element is in the diagonal of the matrix. I have tried the following code:
diagvector <- diag(myvector)
But then it just show the first number. I think I only can use that code if my vector have the following form: num [1:2464].
So how do I a) change the format from num [1:2464, 1] to num [1:2464] for my vector, or b) take the diagonal to my vector with the format num [1:2464, 1]?
Your "column vector" is actually a matrix as it has two dimensions, but it can be formed into a vector.
myvector <- matrix(1:2464, 1)
diagvector <- diag(c(myvector))
diagvector
[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [,13] ...
[1,] 1 0 0 0 0 0 0 0 0 0 0 0 0
[2,] 0 2 0 0 0 0 0 0 0 0 0 0 0
[3,] 0 0 3 0 0 0 0 0 0 0 0 0 0
[4,] 0 0 0 4 0 0 0 0 0 0 0 0 0
[5,] 0 0 0 0 5 0 0 0 0 0 0 0 0
[6,] 0 0 0 0 0 6 0 0 0 0 0 0 0
[7,] 0 0 0 0 0 0 7 0 0 0 0 0 0
[8,] 0 0 0 0 0 0 0 8 0 0 0 0 0
[9,] 0 0 0 0 0 0 0 0 9 0 0 0 0
[10,] 0 0 0 0 0 0 0 0 0 10 0 0 0
[11,] 0 0 0 0 0 0 0 0 0 0 11 0 0
[12,] 0 0 0 0 0 0 0 0 0 0 0 12 0
[13,] 0 0 0 0 0 0 0 0 0 0 0 0 13
...
Or:
myvector <- matrix(1:2464, 1)
diagvector <- diag(length(myvector)) * c(myvector)
diagvector
I'm making a barebones game of Minesweeper in TI-Basic for my TI-84 Plus. I'm stuck on adding numbers around mines. I have the number 9 representing the bombs since TI-Basic doesn't allow other data types in matrices.
For example I have the matrix
0 0 0 0 0 0 0 9 0
0 9 0 0 0 0 0 0 0
0 0 0 0 0 9 0 0 0
0 0 9 0 9 0 0 0 0
0 0 0 0 9 0 0 0 0
9 0 0 0 0 0 0 0 0
0 9 0 0 0 0 0 0 0
0 0 0 0 0 9 0 0 0
0 0 0 0 0 0 0 0 9
I'd like to change this to
1 1 1 0 0 0 1 9 1
1 9 1 0 1 1 2 1 1
1 2 2 0 2 9 1 0 0
0 1 9 3 9 3 1 0 0
1 2 0 3 9 2 0 0 0
9 2 1 1 1 1 0 0 0
2 9 1 0 1 1 1 0 0
1 1 1 0 1 9 1 1 1
0 0 0 0 1 1 1 1 9
Sorry if I missed any numbers, I did that manually.
Any ideas how I could do this in TI-Basic
Ok I know this is really old, but I came up with a solution that I never shared. So if anyone is ever looking over this, here's what I did. First, I set up a matrix with the dimensions of the minefield. Then, I added an extra couple dimensions to the matrix, and filled it with -99. Here's how it would work on my original
0 0 0 0 0 0 0 9 0
0 9 0 0 0 0 0 0 0
0 0 0 0 0 9 0 0 0
0 0 9 0 9 0 0 0 0
0 0 0 0 9 0 0 0 0 ->
9 0 0 0 0 0 0 0 0
0 9 0 0 0 0 0 0 0
0 0 0 0 0 9 0 0 0
0 0 0 0 0 0 0 0 9
-99 -99 -99 -99 -99 -99 -99 -99 -99 -99 -99
-99 0 0 0 0 0 0 0 9 0 -99
-99 0 9 0 0 0 0 0 0 0 -99
-99 0 0 0 0 0 9 0 0 0 -99
-99 0 0 9 0 9 0 0 0 0 -99
-99 0 0 0 0 9 0 0 0 0 -99
-99 9 0 0 0 0 0 0 0 0 -99
-99 0 9 0 0 0 0 0 0 0 -99
-99 0 0 0 0 0 9 0 0 0 -99
-99 0 0 0 0 0 0 0 0 9 -99
-99 -99 -99 -99 -99 -99 -99 -99 -99 -99 -99
Then, iterate through each cell in the inner 9x9 matrix (the ones that aren't negative).
Then, go through a loop searching for mines around that cell.
For(I,2,10)
For(J,2,10)
For(K,-1,1)
If [M](I+K,J+L)>8 //A neighbor can't be greater than eight unless it's a mine.
Then
For(L,-1,1)
[M](I+K,J+L)+1->[M](I+K,J+L)+1
End
End
End
End
End
This loop goes through all neighbors and if one is a mine, it adds one to that cell.
The negative numbers are ignored entirely this way, and you don't have to hard-code for corners and sides.
Code is available on my github: ti84sweeper
There's a very simple way of doing it, but it probably wouldn't be very fast. First though, use a double for loop to loop through every cell in the matrix :
For(a, 1, 9
For(b, 1, 9
End
End
Then, when you're checking the neighbors you'll have to account for corners and edges that don't have eight spaces around them.
For(a, 1, 9
For(b, 1, 9
If a>1 and a <9 and b>1 and b<9
Then
End
End
End
Now, we can check how many spaces around us are 9's. We'll use a counter "c" to count how many times we find a 9. It's tedious, but it's the simplest way
0->c
For(a, 1, 9
For(b, 1, 9
If a>1 and a <9 and b>1 and b<9
Then
c + ([a](a-1, b-1)=9) + ([a](a-1, b)=9) + ([a](a-1, b+1)=9) + ([a](a, b-1)=9) + ([a](a,
b+1)=9) + ([a](a+1, b-1)=9) + ([a](a+1, b)=9) + ([a](a+1, b+1)=9)->c
End
c->[a](a, b)
End
End
I left out accounting for the corners and the edges, you'll just have to add another if statementHope this helped!
I have a matrix. I want to know it whether sparse or not. Is there any function in matlab to evaluate that property? I tried to used issparse function, but it always returns 0(not sparse). For example, my matrix (27 by 27) is
A=
[ 1 0 0 0 0 1 1 1 0 0 1 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0
1 1 0 0 0 0 1 0 1 0 0 1 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0
1 1 1 0 0 0 0 1 0 1 0 0 1 0 0 0 0 0 0 1 1 0 0 0 0 0 0
0 1 1 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 0 1 1 0 0 0 0 0
0 0 1 1 1 0 0 1 0 1 0 0 0 0 1 0 0 0 0 0 0 1 1 0 0 0 0
0 0 0 1 1 1 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 1 1 0 0 0
0 0 0 0 1 1 1 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 1 1 0 0
250 243 247 245 244 244 244 122 61 144 72 36 18 9 4 2 1 1 0 0 0 0 0 0 0 0 0
151 197 236 118 181 212 106 53 26 13 136 68 34 17 8 4 2 0 1 0 0 0 0 0 0 0 0
24 12 6 3 143 201 234 117 180 90 45 152 76 38 19 9 4 0 0 1 0 0 0 0 0 0 0
18 9 138 69 172 86 165 220 224 112 56 28 128 64 32 16 8 0 0 0 1 0 0 0 0 0 0
27 131 207 103 189 94 47 153 194 239 119 59 29 128 64 32 16 0 0 0 0 1 0 0 0 0 0
44 22 133 204 232 116 58 147 199 237 248 124 62 31 129 64 32 0 0 0 0 0 1 0 0 0 0
238 119 181 90 45 152 76 38 19 135 205 232 116 58 29 128 64 0 0 0 0 0 0 1 0 0 0
48 24 12 6 3 143 201 100 50 25 130 207 233 116 58 29 128 0 0 0 0 0 0 0 1 0 0
168 84 42 21 132 66 33 158 79 39 19 135 205 232 116 58 29 0 0 0 0 0 0 0 0 1 0
235 117 58 29 128 64 32 16 8 4 2 1 142 201 234 117 58 0 0 0 0 0 0 0 0 0 1
0 0 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0
0 1 1 0 0 0 0 1 1 0 0 0 1 1 1 0 0 0 0 0 1 1 0 0 0 0 0
1 1 1 1 1 1 1 1 0 1 1 1 1 1 0 1 1 1 1 0 0 0 0 0 0 0 0
0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 1 0 0 0 0 1 0
0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 1 1
0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 1 0 0 1 0 0
0 0 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 0 0 1 0 0 1 0 0 0 1
0 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 1 0 0 0 0
0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 0 1 1 0 0 1 0 0 0 0 1 0
0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 1 0 0 0 0 1 1 0 0 0 0]
This is figure for above matrix
This seemingly easy question is quite difficult to answer. There is actually no known standard that determines whether a matrix is sparse or full.
However, the most common measure I know is to measure a matrix's sparsity. This is simply the fraction of the total number of zeroes over the total number of elements. If this exceeds some sensible threshold, then you could say that the matrix is sparse.
If you're given the matrix A, perhaps something like this:
sparsity = (numel(A) - nnz(A)) / numel(A);
numel determines the total number of elements in the matrix A and nnz determines the total number of non-zero elements. Therefore, numel(A) - nnz(A) should give you the total number of zero elements.
So, going with the threshold idea, this is what I was talking about:
is_sparse = sparsity > tol;
tol would be a fraction from [0,1], so something like 0.75 could work. This would mean that if 75% of your matrix consisted of zeroes, this could be a sparse matrix. It's all heuristic though. Choose a threshold that you think makes the most sense.
I have a question in sort of connected component. I have a binary image ( onlye 0 and 1) I run the function from matlab:
f=
1 0 0 1 0 0 0 1 0 0
1 1 0 1 1 1 0 0 1 0
0 0 0 0 0 0 0 1 1 1
1 0 0 0 1 0 1 0 1 1
1 1 0 0 0 0 0 1 1 1
0 0 0 1 0 0 1 0 0 0
0 0 0 1 0 1 1 0 1 1
1 1 0 0 1 0 0 0 1 0
1 1 0 1 1 1 0 1 0 0
1 1 0 0 1 0 0 0 1 0
[L num]=bwlabel(f);
suppose that they give me the ma trix:
1 0 0 4 0 0 0 5 0 0
1 1 0 4 4 4 0 0 5 0
0 0 0 0 0 0 0 5 5 5
2 0 0 0 6 0 5 0 5 5
2 2 0 0 0 0 0 5 5 5
0 0 0 5 0 0 5 0 0 0
0 0 0 5 0 5 5 0 7 7
3 3 0 0 5 0 0 0 7 0
3 3 0 5 5 5 0 7 0 0
3 3 0 0 5 0 0 0 7 0
But you can see in this resul, the order of matrix is follow the column. Now I want to change this in to the oder rows, that mean number 4 is 2 , number 5 is 3... so on.
The oder is left-> right and top -> down. How can I do that ( the oder of reading )??
Thank you so much
f=f';
[L num]=bwlabel(f);
L=L';
does this solves your problem?
how to convert these 7-segment decoder to boolean expression??
BCD 7-Segment decoder
A B C D a b c d e f g
0 0 0 0 0 0 0 0 0 0 1
0 0 0 1 1 0 0 1 1 1 1
0 0 1 0 0 0 1 0 0 1 0
0 0 1 1 0 0 0 0 1 1 0
0 1 0 0 1 0 0 1 1 0 0
0 1 0 1 0 1 0 0 1 0 0
0 1 1 0 0 1 0 0 0 0 0
0 1 1 1 0 0 0 1 1 1 1
1 0 0 0 0 0 0 0 0 0 0
1 0 0 1 0 0 0 0 1 0 0
I suggest you use a karnough map.
You'll need to use one for each result column, so 7 4x4 tables.
There are even a few karough map generators on the web that you can use.