Skip to content

Python tools to create, maintain and extend a graph database for computer simulations of polymers.

License

Notifications You must be signed in to change notification settings

MartinWenge/neo4BFMPolymers

Repository files navigation

example of polymer and simulations in te database

neo4BFMPolymers

Access a neo4j database to efficiently organize simulations of polymers, using the bond fluctuation model (BFM) and the LeMonADE library.

GitHub issues open CircleCI

Python interface for a graph based database

The neo4BFMPolymers tool collection contains several python functions to add polymers, simulation setups, simulation parameters and relations between the various nodes in a neo4j database. The available node types and connection types are defined in the function definitions, to avoid doubling of nodes with similar meaning.

The available functions can be used as a python module by exporting the jupyter-notebooks to a plain python file or directly in the notebook.

Getting Started

For a local usage, it is recommended to install the desktop version of neo4j and access a plain database. The python library py2neo is used to access the database (default with username neo4j and host bolt://localhost:7687) via the Graph class of py2neo with the jupyter-notebooks provided in this repository. Once the connection to the database is working, the available functions allow you to add nodes, connections and data to the database. You can insert the data manually, or parse bfm files or output files from LeMonADE for large amounts of data.

Basic Usage

Get the library from (test) pypi

pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple neo4polymer

Setup database connection

To apply actions on the database, setup an instance of the Graph class of the py2neo library and pass it to the neo4Polymer class.

from py2neo import Graph
import neo4Polymer
# connect the graph with (default local) database -> it should be running already
graph = Graph(scheme="bolt", host="localhost", port=7687, auth=('<username>', '<password>'))
# setup instance of the neo4Polymer - BFM file interface
myNeo4Polymer = neo4Polymer.neo4BFMPolymer(graph)

Manually add nodes

To add nodes, find the interfaces you need from the docs and run them on the neo4Polymer class instance.

# add Linear Chain as Polymer node:
myNeo4Polymer.addNewPolymer("Linear Chain")
# add SimulationProject node
myNeo4Polymer.addNewSimulationProject("Linear polymer solutions")
# connect Polymer node and simulation project
myNeo4Polymer.connectSimulationToPolymer("Linear Chain", "Linear polymer solutions")
# add SimulationRun node
simRunName = "Linear polymer solutions"
myNeo4Polymer.addSimulationRunToSimulationProject("short_chain_dilute",simRunName)
# add some meta information to SimulationRun node
myNeo4Polymer.addLinearChainLengthToSimulationRun(simRunName,32)
myNeo4Polymer.addVolumeFractionToSimulationRun(simRunName,0.05)

Parse files to add content

To add information from a file, use the file reader functions for supported file formats.

# read in bfm / radius of gyration / bond length file
myNeo4Polymer.addBFMFileToDatabase(simRunName,"<path/to/file>")
myNeo4Polymer.addAnyRadiusOfGyrationFileToDatabase(simRunName,"<path/to/file>")
myNeo4Polymer.addAnyBondLengthFileToDatabase(simRunName, "<path/to/file>")

Run search queries to get

Once there are some information, neo4polymer provides some search query templates, returning pandas data frames as result.

# setup instance of search request class connected to the graph
myRequest = neo4Polymer.neo4PolymerRequests(graph)
# get "Linear polymer solutions" and some additional information from the above example graph
print(myRequest.getSimulationProjectsByPolymer("Linear Chain"))
# get "short_chain_dilute" and some additional information from the above example graph
print(myRequest.getSimulationRunsBySimulationProject(simRunName, "<path/to/file>"))

Documentation

The documentation is done with DocStrings. To call a documentation, run help( class or function ).

Dependencies

Naturally, the python tools need a running neo4j database that can be accessed by the Graph class.

The following python libraries are used:

Tests

  • the python test framework pytest is used
  • run the tests from the head directory by pytest tests/

Linter

  • the python linter flake8 is used with the call flake8 --statistics --ignore E501,E402,E221,F401
  • -> the maximum length of the line and imports at the very beginning of the -py files are ignored
  • -> imported but unused warning from __init__.py files
  • the linter is not included in the CI pipeline, but it is recommended to use it

Continous integration