Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
SWP-Algo-Conway-Graph
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
adip00
SWP-Algo-Conway-Graph
Commits
b360a1e5
"...dune-solvers.git" did not exist on "c031b07735cf0a28bd533d8e83d858f8fc6fed18"
Commit
b360a1e5
authored
2 years ago
by
adip00
Browse files
Options
Downloads
Patches
Plain Diff
update noob.ipynb
parent
8da43221
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
noob.ipynb
+3
-1
3 additions, 1 deletion
noob.ipynb
with
3 additions
and
1 deletion
noob.ipynb
+
3
−
1
View file @
b360a1e5
...
@@ -738,7 +738,9 @@
...
@@ -738,7 +738,9 @@
"%%opts Chord [height=1000 width=1000 labels=\"element\"]\n",
"%%opts Chord [height=1000 width=1000 labels=\"element\"]\n",
"%%opts Chord (node_color=\"element\" node_cmap=\"Category20\" edge_color=\"source_element\" edge_cmap='Category20')\n",
"%%opts Chord (node_color=\"element\" node_cmap=\"Category20\" edge_color=\"source_element\" edge_cmap='Category20')\n",
"chord = hv.Chord((plot_data, labels))\n",
"chord = hv.Chord((plot_data, labels))\n",
"chord"
"chord\n",
"\n",
"# output not visible here, dunno why, but saved as chord_plot.png"
]
]
},
},
{
{
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` python
``` python
from CONWAY_table_data import evo_table
from CONWAY_table_data import evo_table
import numpy as np
import numpy as np
import pandas as pd
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib.pyplot as plt
```
```
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` python
``` python
evo_mapping_dict = {row[1]: row[2].split() for row in evo_table}
evo_mapping_dict = {row[1]: row[2].split() for row in evo_table}
column_names = ['atomic_num', 'element', 'evolution', 'string', 'string_evolution']
column_names = ['atomic_num', 'element', 'evolution', 'string', 'string_evolution']
df = pd.DataFrame(evo_table, columns=column_names)
df = pd.DataFrame(evo_table, columns=column_names)
```
```
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` python
``` python
evo_mapping_dict['He']
evo_mapping_dict['He']
```
```
%% Output
%% Output
['Hf', 'Pa', 'H', 'Ca', 'Li']
['Hf', 'Pa', 'H', 'Ca', 'Li']
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` python
``` python
df.head()
df.head()
```
```
%% Output
%% Output
atomic_num element evolution \
atomic_num element evolution \
0 1 H H
0 1 H H
1 2 He Hf Pa H Ca Li
1 2 He Hf Pa H Ca Li
2 3 Li He
2 3 Li He
3 4 Be Ge Ca Li
3 4 Be Ge Ca Li
4 5 B Be
4 5 B Be
string \
string \
0 22
0 22
1 13112221133211322112211213322112
1 13112221133211322112211213322112
2 312211322212221121123222112
2 312211322212221121123222112
3 111312211312113221133211322112211213322112
3 111312211312113221133211322112211213322112
4 1321132122211322212221121123222112
4 1321132122211322212221121123222112
string_evolution
string_evolution
0 22
0 22
1 11132132212312211322212221121123222112
1 11132132212312211322212221121123222112
2 13112221133211322112211213322112
2 13112221133211322112211213322112
3 3113112221131112211322212312211322212221121123...
3 3113112221131112211322212312211322212221121123...
4 111312211312113221133211322112211213322112
4 111312211312113221133211322112211213322112
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` python
``` python
def get_encoding(e):
def get_encoding(e):
#print(e)
#print(e)
one_hot = np.zeros((92))
one_hot = np.zeros((92))
elements = evo_mapping_dict[e]
elements = evo_mapping_dict[e]
#print(elements)
#print(elements)
indices = (df.loc[df['element'].isin(elements), 'atomic_num']-1).tolist()
indices = (df.loc[df['element'].isin(elements), 'atomic_num']-1).tolist()
one_hot[indices] = 1
one_hot[indices] = 1
return one_hot
return one_hot
```
```
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` python
``` python
onehot = []
onehot = []
for e in df['element']:
for e in df['element']:
onehot.append(get_encoding(e))
onehot.append(get_encoding(e))
onehot = np.array(onehot)
onehot = np.array(onehot)
print(onehot.shape)
print(onehot.shape)
```
```
%% Output
%% Output
(92, 92)
(92, 92)
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` python
``` python
# Create a DataFrame with the connection data
# Create a DataFrame with the connection data
connections_df = pd.DataFrame(onehot, columns=range(1, 93), index=range(1, 93))
connections_df = pd.DataFrame(onehot, columns=range(1, 93), index=range(1, 93))
connections_df.head()
connections_df.head()
```
```
%% Output
%% Output
1 2 3 4 5 6 7 8 9 10 ... 83 84 85 86 \
1 2 3 4 5 6 7 8 9 10 ... 83 84 85 86 \
1 1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 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 0.0 0.0 0.0 0.0 ... 0.0 0.0 0.0 0.0
2 1.0 0.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ... 0.0 0.0 0.0 0.0
2 1.0 0.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ... 0.0 0.0 0.0 0.0
3 0.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ... 0.0 0.0 0.0 0.0
3 0.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ... 0.0 0.0 0.0 0.0
4 0.0 0.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ... 0.0 0.0 0.0 0.0
4 0.0 0.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ... 0.0 0.0 0.0 0.0
5 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0 ... 0.0 0.0 0.0 0.0
5 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0 ... 0.0 0.0 0.0 0.0
87 88 89 90 91 92
87 88 89 90 91 92
1 0.0 0.0 0.0 0.0 0.0 0.0
1 0.0 0.0 0.0 0.0 0.0 0.0
2 0.0 0.0 0.0 0.0 1.0 0.0
2 0.0 0.0 0.0 0.0 1.0 0.0
3 0.0 0.0 0.0 0.0 0.0 0.0
3 0.0 0.0 0.0 0.0 0.0 0.0
4 0.0 0.0 0.0 0.0 0.0 0.0
4 0.0 0.0 0.0 0.0 0.0 0.0
5 0.0 0.0 0.0 0.0 0.0 0.0
5 0.0 0.0 0.0 0.0 0.0 0.0
[5 rows x 92 columns]
[5 rows x 92 columns]
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` python
``` python
import holoviews as hv
import holoviews as hv
from holoviews import opts
from holoviews import opts
from bokeh.palettes import Blues, Viridis
from bokeh.palettes import Blues, Viridis
hv.extension('bokeh')
hv.extension('bokeh')
```
```
%% Output
%% Output
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` python
``` python
# Compute the number of connections for each element
# Compute the number of connections for each element
num_connections = connections_df.sum(axis=1)
num_connections = connections_df.sum(axis=1)
# Create the source data for the chord diagram
# Create the source data for the chord diagram
data = connections_df.stack().reset_index()
data = connections_df.stack().reset_index()
data.columns = ['source', 'target', 'value']
data.columns = ['source', 'target', 'value']
color = [str(num_connections[i]) for i in data['source']]
color = [str(num_connections[i]) for i in data['source']]
data['color'] = color
data['color'] = color
# Create a dictionary to map the atomic numbers to element names
# Create a dictionary to map the atomic numbers to element names
atomic_number_to_element = {row[0]: row[1] for row in evo_table}
atomic_number_to_element = {row[0]: row[1] for row in evo_table}
# Map the atomic numbers to element names in the data DataFrame
# Map the atomic numbers to element names in the data DataFrame
data['source_element'] = data['source'].map(atomic_number_to_element)
data['source_element'] = data['source'].map(atomic_number_to_element)
data['target_element'] = data['target'].map(atomic_number_to_element)
data['target_element'] = data['target'].map(atomic_number_to_element)
data = data[data['value'] != 0]
data = data[data['value'] != 0]
data = data.sort_values(by=['color'], ascending=False)
data = data.sort_values(by=['color'], ascending=False)
print(data.head())
print(data.head())
plot_data = data[['source_element', 'target_element']]
plot_data = data[['source_element', 'target_element']]
```
```
%% Output
%% Output
source target value color source_element target_element
source target value color source_element target_element
1866 21 27 1.0 5.0 Sc Co
1866 21 27 1.0 5.0 Sc Co
1840 21 1 1.0 5.0 Sc H
1840 21 1 1.0 5.0 Sc H
1906 21 67 1.0 5.0 Sc Ho
1906 21 67 1.0 5.0 Sc Ho
1930 21 91 1.0 5.0 Sc Pa
1930 21 91 1.0 5.0 Sc Pa
92 2 1 1.0 5.0 He H
92 2 1 1.0 5.0 He H
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` python
``` python
labels = list(set(data['source_element'].unique().tolist() + data['target_element'].unique().tolist()))
labels = list(set(data['source_element'].unique().tolist() + data['target_element'].unique().tolist()))
labels = hv.Dataset(pd.DataFrame(labels, columns=['element']))
labels = hv.Dataset(pd.DataFrame(labels, columns=['element']))
```
```
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` python
``` python
%%opts Chord [height=1000 width=1000 labels="element"]
%%opts Chord [height=1000 width=1000 labels="element"]
%%opts Chord (node_color="element" node_cmap="Category20" edge_color="source_element" edge_cmap='Category20')
%%opts Chord (node_color="element" node_cmap="Category20" edge_color="source_element" edge_cmap='Category20')
chord = hv.Chord((plot_data, labels))
chord = hv.Chord((plot_data, labels))
chord
chord
# output not visible here, dunno why, but saved as chord_plot.png
```
```
%% Output
%% Output
:Chord [source_element,target_element]
:Chord [source_element,target_element]
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` python
``` python
```
```
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment