Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use element_color node attribute in drawing #84

Open
schatzsc opened this issue Oct 14, 2022 · 1 comment
Open

Use element_color node attribute in drawing #84

schatzsc opened this issue Oct 14, 2022 · 1 comment

Comments

@schatzsc
Copy link
Collaborator

    We're currently not using the properties `element_name` and `element_color`. Is there a future use case for those?

Originally posted by @JanCBrammer in #81 (comment)

@schatzsc
Copy link
Collaborator Author

Some quick and dirty code how to pass on element_color to nx.kamada_kawai_layout(G):

node_color_list = []
for i in G:
    element_color = G.nodes.data('element_color')[i]
    if element_color == "lightgrey":
        element_color = "0xD3D3D3"
    color_code = '#'+element_color[2:]
    node_color_list.append(color_code)
node_size = 1 / G.order() * 10000
options = { "with_labels": False, "font_size": 18, "node_size": node_size, "edgecolors": "black", "linewidths": 2, "width": 2, "node_color": node_color_list }
positions = nx.kamada_kawai_layout(G)
pos_attrs = {}
for node, coords in positions.items():
    pos_attrs[node] = (coords[0], coords[1])
    node_attrs1 = nx.get_node_attributes(G, 'element_symbol')
    node_attrs2 = nx.get_node_attributes(G, 'atomic_number')
    custom_node_attrs1 = {}
    custom_node_attrs2 = {}
for node, attr in node_attrs1.items():
    custom_node_attrs1[node] = str(node)
    custom_node_attrs2[node] = attr
for node, attr in node_attrs2.items():
    custom_node_attrs2[node] = custom_node_attrs2[node]+"\n"+str(attr)
nx.draw(G, positions, **options)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant