Configuration exporters¶
Interface for configuration-exporting classes. |
|
Export configurations to the cogli file format, used for visualisation purposes. |
|
Export configurations to the oxDNA file format. |
|
Export configurations to the LAMMPS data file format. |
-
class
baggianalysis.core.
BaseExporter
(self: baggianalysis.core.BaseExporter) → None¶ Bases:
pybind11_builtins.pybind11_object
Interface for configuration-exporting classes.
The default constructor does not take any parameters.
-
write
(self: baggianalysis.core.BaseExporter, system: baggianalysis.core.System, filename: str) → None¶ Print out a single system.
-
write_topology
(self: baggianalysis.core.BaseExporter, arg0: baggianalysis.core.System, arg1: str) → None¶ Some formats have a topology file on top of configuration (and/or trajectory) files. By default this method is called by both
write()
andwrite_topology()
and hence should be extended by child classes that export to formats that use topology files.- Parameters
system –
-
-
class
baggianalysis.core.
Cogli1Exporter
(*args, **kwargs)¶ Bases:
baggianalysis.core.BaseExporter
Export configurations to the cogli file format, used for visualisation purposes.
The appearance of particles can be controlled via callback functions, while a bond connecting two particles is drawn as a cylinder. The size and the colour of the cylinder is a third of the size and the colour of the particle having the smallest index in the pair.
Overloaded function.
__init__(self: baggianalysis.core.Cogli1Exporter) -> None
The default constructor makes the exporter print each particle as a red sphere of radius 0.5.
__init__(self: baggianalysis.core.Cogli1Exporter, mapper: Callable[[baggianalysis.core.Particle], baggianalysis.core.Cogli1Particle]) -> None
This constructor takes as a parameter a callable that maps each particle into a
Cogli1Particle
sphere that will be interpreted by the exporter and printed in cogli1 format.An example of such a callable is the following:
def cogli1_mapper(p): c_p = ba.Cogli1Particle() if p.position[0] > 0: c_p.size = 1.0 c_p.color = "0,1,0" if p.position[1] > 0: c_p.show = False return c_p
The function defined above will give all those particles that have an x coordinate larger than 0 a size of 1.0 and a green color. Particles with a y coordinate larger than 0 will be hidden. The other particles will be red and have a size of 0.5.
- Parameters
mapper (callable) – A callable that takes a particle and returns a
Cogli1Particle
.
__init__(self: baggianalysis.core.Cogli1Exporter, converter: Callable[[baggianalysis.core.Particle], str], dummy: bool) -> None
This constructor takes two parameters: a callable that maps each particle into a string and a dummy boolean required to make the c++->Python conversion work. It can be used to fully customise the output. The following example uses such flexibility to use cogli1 to visualise patchy particles:
delta = 0.24 cosmax = 0.98 theta = math.acos(cosmax) def converter(p): ret = "%lf %lf %lf @ 0.5 C[red] M " % (p.position[0], p.position[1], p.position[2]) for patch in p.orientation_vectors: patch_pos = patch * (0.5 + delta) ret += "%lf %lf %lf %lf C[blue] " % (patch_pos[0], patch_pos[1], patch_pos[2], theta) return ret
The function defined above will show the patches associated to the particles as blue cones of the given length and width in cogli1.
- Parameters
converter (callable) – A callable that takes a particle and returns a string.
dummy (bool) – A dummy boolean. Its value does not affect the behaviour of the exporter.
-
class
baggianalysis.core.
Cogli1Particle
(self: baggianalysis.core.Cogli1Particle) → None¶ Bases:
pybind11_builtins.pybind11_object
A utility class that encapsulates a sphere. It is used by
Cogli1Exporter
to customise its output.By default, the sphere is visible, has a size of 0.5 and a red color.
-
property
color
¶ The color of the sphere. It can be a name (“red”) or an RGB string (“1,0,0”). Defaults to “red”.
- Type
-
property
-
class
baggianalysis.core.
GenericOxDNAExporter
(self: baggianalysis.core.GenericOxDNAExporter, arg0: bool) → None¶ Bases:
baggianalysis.core.BaseExporter
Export configurations to the oxDNA file format. The exporter will generate a topology and a configuration file. Note that the filename passed to the
write()
method is used as-is for the configuration file and as a suffix, prefixed bytopology_
, for the topology file.The constructor takes one parameter which tells the exporter whether the topology line should also contain the number of particles of type A.
- Parameters
also_print_N_A (bool) – If True, the exporter will print the number of particles of type A in addition to the number of particles in the topology file.
-
class
baggianalysis.core.
LAMMPSDataFileExporter
(self: baggianalysis.core.LAMMPSDataFileExporter, arg0: str) → None¶ Bases:
baggianalysis.core.BaseExporter
Export configurations to the LAMMPS data file format.
Note that LAMMPS requires particle indexes and types to be positive-definite integers. By contrast, baggianalysis uses zero-based indexes and string types. If the system to be printed does not contain LAMMPS-valid values (which is common if baggianalysis is being used to convert between different formats) then the exporter will try to fix them either by shifting values so they start from 1 or, in the case of string types, by using 1-based sequences.
The constructor takes one mandatory argument.