Skip to content

Plugin for the CRIPT Python SDK to convert the data graphs to Networkx and Graphiz Dot.

License

Notifications You must be signed in to change notification settings

InnocentBug/cript_graph

Repository files navigation

CRIPT Graph Operation Plugin for the Python SDK

CI Tests https://trunk.io check

This repository contains a plugin designed to work with the Python SDK of the CRIPT project. The CRIPT project is an innovative initiative in polymer technology. For more information about the project, please visit the CRIPT website.

The Python SDK, which this plugin complements, can be found here. It provides a powerful set of tools for working with CRIPT data graphs.

Installation

To install the CRIPT Graph Operation Plugin, you can use pip:

pip install cript-graph

NetworkX Graph Conversion

The plugin offers a convenient conversion function to convert a CRIPT SDK data graph into a NetworkX graph. NetworkX is a widely-used Python package for graph operations.

Here's an example of how to use the conversion function:

import cript
import cript_graph

with cript.API(None, None) as api:
    # CRIPT SDK code to build or download the data graph
    project = cript.Project(...)
    # ...
    networkx_graph = cript_graph.get_networkx_graph(project)
    # Perform NetworkX graph operations
    print(networkx_graph.nodes)
    print(networkx_graph.edges)

Please refer to the documentation of the get_networkx_graph function for detailed information about the resulting graph.

Graphviz Dot Visualization

Visualizing the entire data graph of CRIPT can sometimes be challenging, especially when more detailed information is required, such as for debugging purposes. In such cases, the Graphviz dot tool can be a valuable resource.

The plugin provides a tool to generate a visual representation of the data graph using the Graphviz dot language.

Here's an example of how to generate a dot file using the plugin:

import cript
import cript_graph

with cript.API(None, None) as api:
    # CRIPT SDK code to build or download the data graph
    project = cript.Project(...)
    # ...
    # Create an intermediate NetworkX graph
    networkx_graph = cript_graph.get_networkx_graph(project)
    # Generate the graph representation in the dot language
    dot_string = cript_graph.get_dot_graph(networkx_graph)

You can write the resulting dot language string to a file:

with open("graph.dot", "w") as file_handle:
    file_handle.write(dot_string)

To convert the dot file to an SVG graph using the Graphviz command line tool:

dot -Tsvg graph.dot > graph.svg

Alternatively, you can use the pydot package to handle the generation of the visualization from within Python:

import pydot

pydot_graph = pydot.graph_from_dot_data(dot_string)
pydot_graph.write_svg("graph.svg")

An example graph of CRIPT visualized using Graphviz dot:

Example Graph of CRIPT visualized via Graphviz dot

References

Walsh, D. J., Zou, W., Schneider, L., Mello, R., Deagen, M. E., Mysona, J., ... & Olsen, B. D. (2023). Community Resource for Innovation in Polymer Technology (CRIPT): A Scalable Polymer Material Data Structure.

About

Plugin for the CRIPT Python SDK to convert the data graphs to Networkx and Graphiz Dot.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published