Skip to main content

Plugin for CRIPT Python SDK, convert CRIPT graphs to networkx graphs and dot graphs for vizualization.

Project description

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cript_graph-0.0.0.tar.gz (6.1 kB view hashes)

Uploaded Source

Built Distribution

cript_graph-0.0.0-py3-none-any.whl (5.7 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page