Hi,

I need to be able to calculate the mesh size (pore size) in between the

chains in my (end-linked) polymer network using my LAMMPS data. Does anyone

have any experience doing this either directly in LAMMPS or in a secondary

software package?

Sam,

How do you define the mesh size or pore size?

Do you mean the number of bonds in a loop?

If so, you can try the "simple_cycles()" or "cycle_basis()" functions

in networkx.

http://networkx.lanl.gov/reference/generated/networkx.algorithms.cycles.simple_cycles.html

From this web page:

"A list of circuits, where each circuit is a list of nodes, with the first :

and last node being the same. :

Example: :

>>> G = nx.DiGraph([(0, 0), (0, 1), (0, 2), (1, 2), (2, 0), (2, 1),

(2, 2)]) :

>>> nx.simple_cycles(G) :

[[0, 0], [0, 1, 2, 0], [0, 2, 0], [1, 2, 1], [2, 2]]"

Sam, in this example, the 2nd entry [0, 1, 2, 0] is a loop containing 3 atoms.

This is an unrealistic example for a molecular system because the

other loops are too small (self-loops, or pairs of atoms connected by

multiple bonds). But hopefully it shows how to do it.

--- sample code ---

First, save create a data file for your system, extract the "Bonds"

section and load it into networkx. We covered this in an earlier post

a few days ago:

http://sourceforge.net/mailarchive/message.php?msg_id=29760749

...Then you can iterate through all of the loops in your system and

print out their lengths this way:

cycles = nx.simple_cycles(G)

for cycle in cycles:

print('Number of atoms in loop is: '+str(len(cycle)-1))

1

3

2

2

1

Warning: You will have to take care to eliminate loops which are

compositions of smaller loops. (It might also be necessary to embed

your network onto a plane. I'm not sure. You will have to figure

this out.)

After thinking about it further, perhaps you should use the

"cycle_basis()" function instead.

Take a look at:

http://networkx.lanl.gov/reference/generated/networkx.algorithms.cycles.cycle_basis.html#networkx.algorithms.cycles.cycle_basis

(The picture you showed me was not very planar. It was pretty, though.)

Good luck

Andrew

---- forwarded from earlier email correspondence ----

Hi Andrew,

I am looking for some more help with my analysis. I was wondering if you

would be prepared to help.

I want to know how to find the number of a) loops b) loose ends and if

possible the functionality of nodes (by nodes I mean the particles linking

ends of chains, not every node on the graph). Do you know of some nice

algorithms (sam) that could help me do this instead of me just looking at

the outputted file and counting them.

------- loops -------

For the loops ("cycles"), have you tried using the "simple_cycles()"

command in networkx?

http://networkx.lanl.gov/reference/generated/networkx.algorithms.cycles.simple_cycles.html

For example, once you have created a graph G from the "Bonds" section

of you data file (previous email), you could use

cycles = nx.simple_cycles(G)

num_cycles = len(cycles) #<-- counts the number of loops

If you like, you can check the size of each cycle and throw away small

or trivial cycles first, for example using code like this:

min_size_cycle = 3

cycles = nx.simple_cycles(G)

i=0

while i < len(cycles):

cycle = cycles[i]

if len(cycle)-1 < min_size_cycle:

del cycles[i]

else:

i += 1

num_cycles = len(cycles)

-------- ends --------

Perhaps there's an easier way to count the ends ("terminal nodes" or

"external nodes"), but would this work?

ends =

for n in G.nodes():

if len(G.neighbors(n)) < 2:

ends.append(n)

num_ends = len(ends)

If that does not work, try replacing "for n in G.nodes():" with

"for n in dfs_preorder_nodes(G):"