Main types


Representation of a net as a topological abstraction of a crystal.

D is the dimensionality of the net, which is the number of repeated dimensions of a single connex component. This dimensionality is not necessarily the dimension of the space the crystal is embedded into, which would always be 3 for real space.

T is the numeric type used to store the exact coordinates of each vertex at the equilibrium placement.


A topological genome computed by CrystalNets.jl.

Store both the actual genome (as a PeriodicGraph) and the name of the net, if recognized.

Like for a PeriodicGraph, the textual representation of a TopologicalGenome can be parsed back into a TopologicalGenome:

julia> topology = topological_genome(CrystalNet(PeriodicGraph("2  1 2 0 0  2 1 0 1  2 1 1 0")))

julia> typeof(topology)

julia> PeriodicGraph(topology)  # The actual topological genome, as a PeriodicGraph
PeriodicGraph2D(2, PeriodicEdge2D[(1, 2, (-1,0)), (1, 2, (0,0)), (1, 2, (0,1))])

julia> parse(TopologicalGenome, "hcb") == topology

The result of a topology computation on a structure with different Clustering options.

Its representation includes the name of the clustering options along with their corresponding genome. It is omitted if there is only one clustering option which is Auto.

Like for a TopologicalGenome (or a PeriodicGraph), the textual representation of a TopologyResult can be parsed back to a TopologyResult:

julia> mof5 = joinpath(dirname(dirname(pathof(CrystalNets))), "test", "cif", "MOF-5.cif");

julia> topologies = determine_topology(mof5, structure=StructureType.MOF, clusterings=[Clustering.Auto, Clustering.Standard, Clustering.PE])
AllNodes, SingleNodes: pcu
Standard: xbh
PE: cab

julia> typeof(topologies)

julia> parse(TopologyResult, repr(topologies)) == topologies

Main functions

determine_topology(path, options::Options)
determine_topology(path; kwargs...)

Compute the topology of the structure described in the file located at path. This is essentially equivalent to calling topological_genome(UnderlyingNets(parse_chemfile(path, options))).

In the case where the structure is not made of interpenetrating nets, return the topology of the only net.

determine_topology_dataset(path, save, autoclean, showprogress, options::Options)
determine_topology_dataset(path, save=true, autoclean=true, showprogress=true; kwargs...)

Given a path to a directory containing structure input files, compute the topology of each structure within the directory. Return a dictionary linking each file name to the result. The result is a TopologyResult, containing the topological genome, the name if known and the stability of the net. In case of error, the exception is reported.

Warnings will be toggled off (unless force_warn is set) and it is stongly recommended not to export any file since those actions may critically reduce performance, especially for numerous files.

If save is set, the result is also stored in a julia serialized file located at "$path/../results_$i" where i is the lowest integer such that this path does not already exist at the start of the computation. While processing, this path will be used to create a directory storing the current state of the computation: to continue an interrupted computation, simply pass this temporary directory as the path. If autoclean is set, this directory is removed at the end if the computation was successful.

If save is set and autoclean is unset, the directory of temporary files will be renamed into "$path/../results_$i.OLD$j".

If showprogress is set, a progress bar will be displayed representing the number of processed files.

guess_topology(path, options::Options)
guess_topology(path; kwargs...)

Tries to determine the topology of the file at path by passing various options (starting from the provided options if any) until finding a known topology. If none is found, return the topological genome encountered most often through the variation of options.

guess_topology_dataset(path, save, autoclean, showprogress, options::Options)
guess_topology_dataset(path, save=true, autoclean=true, showprogress=true; kwargs...)

Given a path to a directory containing structure input files, guess the topology of each structure within the directory using guess_topology. Return a dictionary linking each file name to the result. The result is the corresponding topology name, if known, or the topological genome preceded by an "UNKNOWN" mention otherwise. In case of error, the result is the exception preceded by a "FAILED with" mention. Finally, if the input does not represent a periodic structure, the result is "non-periodic".

It is strongly recommended to toggle warnings off (through toggle_warning) and not to export any file since those actions may critically reduce performance, especially for numerous files.

The save and autoclean arguments work identically to their counterpart for determine_topology_dataset.

If showprogress is set, a progress bar will be displayed representing the number of processed files.

   parse_chemfile(path, options::Options)
   parse_chemfile(path; kwargs...)

Parse a file given in any recognised chemical format and extract the topological information. Such format can be .cif or any file format recognised by Chemfiles.jl that contains all the necessary topological information.

topological_genome(net::CrystalNet{D,T})::String where {D,T}

Compute the topological genome of a net. The topological genome is an invariant if the net, meaning that it does not depend on its representation. It is also the string representation of a D-periodic graph such that PeriodicGraph{D}(topological_genome(net)) is isomorphic to net.pge.g (except possibly if the ignore_types option is unset).


Options must be passed directly within net.

topological_genome(g::Union{String,PeriodicGraph}, options::Options=Options())
topological_genome(g::Union{String,PeriodicGraph}; kwargs...)

Compute the topological genome of a periodic graph. If given a topological key (as a string), it is converted to a PeriodicGraph first.


Compute the topological genome of each subnet stored in group.


Options must be passed directly within the subnets.

recognize_topology(g::PeriodicGraph, arc=CRYSTALNETS_ARCHIVE)
recognize_topology(genome::AbstractString, arc=CRYSTALNETS_ARCHIVE)

Attempt to recognize a topological genome from an archive of known genomes.


This function does a simple lookup, not any kind of topology computation. To identify the topology of a PeriodicGraph or a CrystalNet x, query topological_genome(x) instead.




Different options, passed as keyword arguments.

Basic options

  • name: a name for the structure.
  • bonding: one of the Bonding options. Default is Bonding.Auto.
  • structure: one of the StructureType options. Default is StructureType.Auto.
  • clusterings: a list of Clustering options. Default is [Clustering.Auto].


For each export option, the accepted values are either a string, indicating the path to the directory in which to store the export, or a boolean, specifying whether or not to do the export. If the value is true, a path will be automatically determined. An empty string is equivalent to false.

  • export_input: the parsed structure, as a .vtf
  • export_trimmed: the parsed structure after iteratively removing all atoms having only one neighbour, as a .vtf
  • export_attributions: the attribution of vertices into SBUs, as a .pdb. Only relevant for the MOF StructureType.
  • export_clusters: the clustering of vertices, as a .vtf
  • export_net: the overall extracted net on which the topology is computed, as a .vtf.
  • export_subnets: each connected component of the overall net as a separate .vtf file. These subnets are defined after grouping vertices according to their Clustering.

Other options

  • ignore_atoms: set of atom symbols to ignore (for instance [:C,:H] will remove carbohydrate solvent residues).
  • ignore_types: disregard atom types to compute the topology, making pcu and pcu-b identical for example (default is true)
  • cutoff_coeff: coefficient used to detect bonds. Default is 0.75, higher values will include bonds that were considered too long before.
  • skip_minimize: assume that the cell is already the unit cell (default is false).
  • dimensions: the set of crystal net dimensions to consider. For instance, putting Set(3) will ensure that only 3-dimensional nets are considered. Default is Set([1,2,3]).
  • cluster_kinds: a ClusterKinds. Default separates organic and inorganic SBUs.
  • ignore_homoatomic_bonds: a Set{Symbol} such that all X-X bonds of the net are removed if X is an atom whose type is in ignore_homoatomic_bonds.
  • max_polyhedron_radius: an integer specifying the maximum number of bonds between two corners of the coordination polyhedron built for the Clustering.PE option. Default is 4.

Miscellaneous options

These boolean options have a default value that may be determined by Bonding, StructureType and Clustering. They can be directly overriden here.

  • bond_adjacent_sbus: bond together SBUs which are only separated by a single C atom.
  • authorize_pruning: remove colliding atoms in the input. Default is true.
  • wider_metallic_bonds: for bond detections, metals have a radius equal to 1.5× their Van der Waals radius. Default is false, unless StructureType is MOF or Zeolite.
  • ignore_homometallic_bonds: when guessing bonds, do not bond two metallic atoms of the same type if they are up to third neighbours anyway. Default is false, unless StructureType is MOF.
  • ignore_metal_cluster_bonds: do not bond two metallic clusters together if they share at least one non-metallic neighbour. Default is false.
  • ignore_low_occupancy: atoms with occupancy lower than 0.5 are ignored. Default is false.
  • detect_paddlewheels: detect paddle-wheel pattern and group them into an inorganic vertex. Default is true.
  • detect_organiccycles: detect organic cycles and collapse all belonging C atoms into a new vertex. Default is true.
  • detect_pe: detect organic points-of-extension (organic atoms bonded to another SBU) and transform them into vertices. Default is true.
  • cluster_simple_pe: cluster adjacent points-of-extension if they are not part of a cycle. Default is true.
  • separate_metals: separate each metal atom into its own vertex (instead of grouping them to form metallic clusters if they are adjacent or bonded by an oxygen). Default is false, unless Clustering is Standard or PEM.
  • split_O_vertex: if a vertex is composed of a single O, remove it and bond together all of its neighbors. Default is true.
  • unify_sbu_decomposition: apply the same rule to decompose both periodic and finite SBUs. Default is false.
  • force_warn: force printing warning and information even during ..._dataset function calls. Default is false.

Internal fields

These fields are for internal use and should not be modified by the user:

  • dryrun: store information on possible options to try (for guess_topology).
  • _pos: the positions of the centre of the clusters collapsed into vertices.
  • error: store the first error that occured when building the net.
  • throw_error: if set, throw the error instead of storing it in the error field.
  • track_mapping: if set to true, this field will contain, at the end of the computation, the mapping from the vertices of the input to the vertices of the returned genome. In the case of determine_topology... calls, the "input" is the file exported through the export_input option. Default is false.

Selection mode for the crystal structure. This choice impacts the bond detection algorithm as well as the clustering algorithm used.

The choices are:

  • Auto: No specific structure information. Use Van der Waals radii for bond detection and Input as Clustering, or EachVertex if the input does not provide residues.
  • MOF: Use Van der Waals radii for non-metallic atoms and larger radii for metals. Detect organic and inorganic clusters and subdivide them according to AllNodes and SingleNodes to identify underlying nets.
  • Cluster: similar to MOF but metallic atoms are not given a wider radius.
  • Zeolite: Same as Auto but use larger radii for metals (and metalloids) and attempt to enforce that each O atom has exactly two neighbours and that they are not O atoms.
  • Guess: try to identify the clusters as in Cluster. If it fails, fall back to Auto.

Selection mode for the detection of bonds. The choices are:

  • Input: use the input bonds. Fail if those are not specified.
  • Guess: guess bonds using a variant of chemfiles / VMD algorithm.
  • Auto: if the input specifies bonds, use them unless they look suspicious (too small or or too large according to a heuristic). Otherwise, fall back to Guess.

The clustering algorithm used to group atoms into vertices.

This choice only affects the creation of a UnderlyingNets from a Crystal, not the Crystal itself, and in particular not the bond detection algorithm.

The basic choices are:

  • Auto: determined using the StructureType.
  • Input: use the input residues as vertices. Fail if some atom does not belong to a residue.
  • EachVertex: each atom is its own vertex. Vertices with degree 2 or lower are iteratively collapsed into edges until all vertices have degree 3 or more.

The next clustering options are designed for MOFs but may target other kinds of frameworks. In all cases, the clusters are refinements on top of already-defined clusters, such as the organic and inorganic SBUs defined by the MOF structure. Except for AllNodes, infinite clusters (such as the inorganic clusters in a rod MOF) are split into new finite clusters using heuristics.

  • SingleNodes: each already-defined cluster is mapped to a vertex.
  • AllNodes: keep points of extension for organic clusters.
  • Standard: make each metallic atom its own vertex and do not bond those together if they share a common non-metallic neighbour.
  • PE: stands for Points of Extension. Keep points of extension for organic clusters, remove metallic centres and bond their surrounding points of extension.
  • PEM: stands for Points of Extension and Metals. Keep points of extension for organic clusters and each metal centre as a separate vertex.
ClusterKinds(sbus, toclassify=Int[])

Description of the different kinds of SBUs there should be when making clusters.

sbus should be a list of set of symbols, each set containing the different elements acceptable in this SBU (an empty set designates all remaining elements). All elements of the same category of the periodic table can be grouped together by putting the name of the category. For example, ClusterKinds([[:Au, :halogen, :nonmetal], [:metal, :metalloid], []]) means that there are three kinds of SBUs:

  • the first kind can only hold halogens, non-metals and Au atoms
  • the second kind can only hold metalloids and metals (except Au)
  • the third kind can hold all the other elements.

The list of possible categories is: :actinide, :noble (for noble gas), :halogen, :lanthanide, :metal, :metalloid and :nonmetal.

toclassify contains the list of SBUs which are not actual SBUs but only groups of atoms waiting to be merged to a neighboring SBU. The neighboring SBU is chosen by order in the sbus list.

The cluster kinds used by default are CrystalNets.ClusterKinds([[:metal, :actinide, :lanthanide], [:C,], [:P, :S], [:nonmetal, :metalloid, :halogen], [:noble]], [3, 4]). This means that all atoms that are either metals, actinides or lanthanides are assigned to class 1 and all C atoms in SBUs of class 2. Afterwards, each group of adjacent P or S atoms is assigned either class 1 if any of its neighbor is of class 1, or class 2 otherwise if any of its neighbor is of class 2. If no such neighbor exist, it is assigned to class 1. Finally, each group of adjacent nonmetals, metalloids and halogens is assigned class 1 or 2 following the same rule as for P and S atoms.

At the end of the procedure, all atoms are thus given a class between 1 and length(sbus) which is not in toclassify. See also find_sbus for the implementation of this procedure.

To determine which SBU kind corresponds to a given atom, use getindex:

julia> sbu_kinds = CrystalNets.ClusterKinds([[:nonmetal, :halogen], [:metal, :F]]);

julia> sbu_kinds[:O] # nonmetal

julia> sbu_kinds[:Au] # metal

julia> sbu_kinds[:F] # specifically F

julia> sbu_kinds[:Ne] # no given SBU kind

If no empty set has been explicitly added to sbus and an element falls outside of the included categories, the returned SBU kind is 0.

An exception is made for nonmetals which are part of an aromatic heterocycle: those will be treated separately and put in the SBU of the corresponding carbons.


Other utilities


Toggle warnings on (if to == true) or off (if to == false). Without an argument, toggle on and off repeatedly at each call.


Toggle exports on (if to == true) or off (if to == false). Without an argument, toggle on and off repeatedly at each call.

export_default(c::Union{PeriodicGraph,CrystalNet,Crystal}, obj=nothing, name=nothing, path=tempdir(); repeats=nothing)

Export a VTF representation of an object at the given path.

obj is a String describing the nature of the object, such as "net", "clusters" or "subnet" for example. Default is string(typeof(c)).

name is a String inserted in the exported file name. Default is a tempname.

repeats is the maximum distance between a represented atom out of the unit cell and one inside. Default is between 2 and 6, depending on obj and the size of the graph.





Can be used to query the topological genome of known nets, as in:

"3 1 2 0 0 0 1 2 0 0 1 1 2 0 1 0 1 2 1 0 0"

julia> topological_genome(CrystalNet(PeriodicGraph(ans)))

It is also possible to directly access the topological genome as a PeriodicGraph by parsing the name as a TopologicalGenome:

julia> parse(TopologicalGenome, "pcu").genome
PeriodicGraph3D(1, PeriodicEdge3D[(1, 1, (0,0,1)), (1, 1, (0,1,0)), (1, 1, (1,0,0))])

julia> string(parse(TopologicalGenome, "nbo").genome) == REVERSE_CRYSTALNETS_ARCHIVE["nbo"]

Parse a .arc Systre archive such as the one used by the RCSR. Return a pair (flag, pairs).

flag is set if the archive corresponds to one generated by a compatible release of CrystalNets. If unset, the genomes of the archive may not be the same as those computed by CrystalNets for the same nets. pairs is a Dict{String,String} whose entries have the form genome => id where id is the name of the net and genome is the topological genome corresponding to this net (given as a string of whitespace-separated values parseable by PeriodicGraph).


Parse a folder containing .arc Systre archives such as the one used by the RCSR. Return a pair (flag, pairs) with the same convention than parse_arc.

clean_default_archive!(custom_arc; validate=true, refresh=true)

Erase the default archive used by CrystalNets.jl to recognize known topologies and replace it with a new one from the file located at custom_arc.

The validate parameter controls whether the new file is checked and converted to a format usable by CrystalNets.jl. If unsure, leave it set.

The refresh optional parameter controls whether the current archive should be replaced by the new default one.


This archive will be kept and used for subsequent runs of CrystalNets.jl, even if you restart your Julia session.

To only change the archive for the current session, use change_current_archive!(custom_arc).

See also refresh_current_archive! for similar uses.


The previous default archive cannot be recovered afterwards, so make sure to keep a copy if necessary. The default archive is the set of ".arc" files located at joinpath(dirname(dirname(pathof(CrystalNets))), "archives").


Set the current archive as the new default archive.


This archive will be kept and used for subsequent runs of CrystalNets.jl, even if you restart your Julia session.

empty_default_archive!(; refresh=true)

Empty the default archive. This will prevent CrystalNets from recognizing any topology before they are explicitly added.

The refresh optional parameter controls whether the current archive should also be emptied.


This empty archive will be kept and used for subsequent runs of CrystalNets.jl, even if you restart your Julia session. If you only want to empty the current archive, do empty!(CrystalNets.CRYSTALNETS_ARCHIVE).

change_current_archive!(custom_arc; validate=true)

Erase the current archive used by CrystalNets.jl to recognize known topologies and replace it with the archive stored in the file located at custom_arc.

The validate optional parameter controls whether the new file is checked and converted to a format usable by CrystalNets.jl. If unsure, leave it set.


This modification will only last for the duration of this Julia session.

If you wish to change the default archive and use it for subsequent runs, use clean_default_archive!.


Using an invalid archive will make CrystalNets.jl unusable. If this happens, simply run refresh_current_archive!() to revert to the default archive.

add_to_current_archive!(id, genome)

Mark genome as the topological genome associated with the name id in the current archive.

The input id and genome are not modified by this operation.


This modification will only last for the duration of this Julia session.

If you wish to save the archive and use it for subsequent runs, use set_default_archive! after calling this function.

make_archive(path, destination=nothing)

Make an archive from the files located in the directory given by path and export it to destination, if specified. Each file of the directory should correspond to a unique topology: if a topology is encountered multiple times, it will be assigned the name of the latest file that bore it.

The archive can then be used with change_current_archive!(destination; validate=false) for instance.

export_arc(path, arc=CRYSTALNETS_ARCHIVE)

Export archive arc to the specified path. If unspecified, the exported archive is the current one.