Skip to content

Commit 812b655

Browse files
committed
refactor: remove plugin arguments from JSON and update main.cpp for option handling
1 parent 67c2bc0 commit 812b655

2 files changed

Lines changed: 54 additions & 139 deletions

File tree

plugin.json

Lines changed: 20 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -21,102 +21,6 @@
2121
}
2222
}
2323
},
24-
{
25-
"id": "plugin-arguments",
26-
"type": "arguments",
27-
"position": {
28-
"x": 528,
29-
"y": 208
30-
},
31-
"data": {
32-
"arguments": {
33-
"arguments": [
34-
{
35-
"argument": "rmsd",
36-
"type": "number",
37-
"label": "RMSD",
38-
"default": 0.1,
39-
"min": 0,
40-
"step": 0.01
41-
},
42-
{
43-
"argument": "minGrainAtomCount",
44-
"type": "number",
45-
"label": "Min Grain Atom Count",
46-
"default": 100,
47-
"min": 1,
48-
"step": 1
49-
},
50-
{
51-
"argument": "adoptOrphanAtoms",
52-
"type": "select",
53-
"label": "Adopt Orphan Atoms",
54-
"default": "true",
55-
"options": [
56-
{
57-
"key": "true",
58-
"label": "True"
59-
},
60-
{
61-
"key": "false",
62-
"label": "False"
63-
}
64-
]
65-
},
66-
{
67-
"argument": "handleCoherentInterfaces",
68-
"type": "select",
69-
"label": "Handle Coherent Interfaces",
70-
"default": "true",
71-
"options": [
72-
{
73-
"key": "true",
74-
"label": "True"
75-
},
76-
{
77-
"key": "false",
78-
"label": "False"
79-
}
80-
]
81-
},
82-
{
83-
"argument": "mergeAlgorithm",
84-
"type": "select",
85-
"label": "Merge Algorithm",
86-
"default": "GraphClusteringAutomatic",
87-
"options": [
88-
{
89-
"key": "GraphClusteringAutomatic",
90-
"label": "Graph Clustering (Automatic)"
91-
},
92-
{
93-
"key": "GraphClusteringManual",
94-
"label": "Graph Clustering (Manual)"
95-
},
96-
{
97-
"key": "MinimumSpanningTree",
98-
"label": "Minimum Spanning Tree"
99-
}
100-
]
101-
},
102-
{
103-
"argument": "mergingThreshold",
104-
"type": "number",
105-
"label": "Merging Threshold",
106-
"default": 0,
107-
"min": 0,
108-
"step": 0.01
109-
},
110-
{
111-
"argument": "outputBonds",
112-
"type": "boolean",
113-
"label": "Output Bonds",
114-
"default": false
115-
}
116-
]
117-
}
118-
}
119-
},
12024
{
12125
"id": "trajectory-context",
12226
"type": "context",
@@ -156,7 +60,7 @@
15660
"binary": "grain-segmentation",
15761
"binaryObjectPath": "__UPLOAD_BINARY_OBJECT_PATH__",
15862
"binaryFileName": "grain-segmentation",
159-
"arguments": "{{ foreach-trajectory-dumps.currentValue.path }} {{ foreach-trajectory-dumps.outputPath }} {{ plugin-arguments.as_str }}",
63+
"arguments": "{{ foreach-trajectory-dumps.currentValue.path }} {{ foreach-trajectory-dumps.outputPath }}",
16064
"timeout": -1
16165
}
16266
}
@@ -172,7 +76,6 @@
17276
"exposure": {
17377
"name": "Grain Segmentation",
17478
"icon": "HiCube",
175-
"id": "grains",
17679
"results": "grains.parquet",
17780
"iterable": ""
17881
}
@@ -189,7 +92,6 @@
18992
"exposure": {
19093
"name": "Grain Model",
19194
"icon": "HiCube",
192-
"id": "grain_atoms",
19395
"results": "atoms.parquet",
19496
"iterable": ""
19597
}
@@ -211,20 +113,6 @@
211113
}
212114
],
213115
"edges": [
214-
{
215-
"id": "edge-metadata-arguments",
216-
"source": "plugin-metadata",
217-
"sourceHandle": "output",
218-
"target": "plugin-arguments",
219-
"targetHandle": "input"
220-
},
221-
{
222-
"id": "edge-arguments-context",
223-
"source": "plugin-arguments",
224-
"sourceHandle": "output",
225-
"target": "trajectory-context",
226-
"targetHandle": "input"
227-
},
228116
{
229117
"id": "edge-context-foreach",
230118
"source": "trajectory-context",
@@ -259,7 +147,26 @@
259147
"sourceHandle": "output",
260148
"target": "grain-model-export",
261149
"targetHandle": "input"
150+
},
151+
{
152+
"id": "edge-plugin-metadata-trajectory-context",
153+
"source": "plugin-metadata",
154+
"sourceHandle": "output",
155+
"target": "trajectory-context",
156+
"targetHandle": "input"
262157
}
263158
]
159+
},
160+
"interface": {
161+
"version": 2,
162+
"provides": {
163+
"volt/grain-segmentation@1": {
164+
"grains": "grains.parquet",
165+
"grain_atoms": "atoms.parquet"
166+
},
167+
"volt/per-atom-properties@1": {
168+
"atoms": "atoms.parquet"
169+
}
170+
}
264171
}
265172
}

src/main.cpp

Lines changed: 34 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include <volt/cli/common.h>
22
#include <volt/grain_segmentation_service.h>
3+
#include <volt/plugin/option_reader.h>
34
#include <oneapi/tbb/global_control.h>
45
#include <tbb/info.h>
56

@@ -9,35 +10,40 @@
910

1011
using namespace Volt;
1112
using namespace Volt::CLI;
13+
using namespace Volt::Plugin;
1214

13-
void showUsage(const std::string& name) {
14-
printUsageHeader(name, "Volt - Grain Segmentation");
15-
std::cerr
16-
<< " --rmsd <float> RMSD threshold for PTM. [default: 0.1]\n"
17-
<< " --minGrainAtomCount <int> Minimum atoms per grain. [default: 100]\n"
18-
<< " --adoptOrphanAtoms <true|false> Adopt orphan atoms. [default: true]\n"
19-
<< " --handleCoherentInterfaces <true|false> Handle coherent interfaces. [default: true]\n"
20-
<< " --mergeAlgorithm <name> Merge algorithm: GraphClusteringAutomatic | GraphClusteringManual | MinimumSpanningTree. [default: GraphClusteringAutomatic]\n"
21-
<< " --mergingThreshold <float> Merge threshold (used by Manual/MST modes). [default: 0]\n"
22-
<< " --outputBonds Output neighbor bonds. [default: false]\n"
23-
<< " --threads <int> Max worker threads (TBB/OMP). [default: auto]\n";
24-
printHelpOption();
15+
static PluginDescriptor buildDescriptor() {
16+
return {
17+
"grain-segmentation",
18+
"Grain Segmentation",
19+
{
20+
{"--rmsd", "float", "RMSD threshold for PTM.", "0.1", {}, ""},
21+
{"--minGrainAtomCount", "int", "Minimum atoms per grain.", "100", {}, ""},
22+
{"--adoptOrphanAtoms", "bool", "Adopt orphan atoms.", "true", {}, ""},
23+
{"--handleCoherentInterfaces", "bool", "Handle coherent interfaces.", "true", {}, ""},
24+
{"--mergeAlgorithm", "enum", "Grain merge algorithm.", "GraphClusteringAutomatic",
25+
{"GraphClusteringAutomatic", "GraphClusteringManual", "MinimumSpanningTree"}, ""},
26+
{"--mergingThreshold", "float", "Merge threshold (used by Manual/MST modes).", "0", {}, ""},
27+
{"--outputBonds", "bool", "Output neighbor bonds.", "false", {}, ""},
28+
}
29+
};
2530
}
2631

2732
int main(int argc, char* argv[]) {
33+
const PluginDescriptor descriptor = buildDescriptor();
34+
2835
if (argc < 2) {
29-
showUsage(argv[0]);
36+
showPluginUsage(argv[0], descriptor);
3037
return 1;
3138
}
32-
39+
3340
std::string filename, outputBase;
3441
auto opts = parseArgs(argc, argv, filename, outputBase);
35-
36-
if (hasOption(opts, "--help") || filename.empty()) {
37-
showUsage(argv[0]);
38-
return filename.empty() ? 1 : 0;
42+
43+
if (auto exitCode = handleIntrospection(argv[0], descriptor, opts, filename)) {
44+
return *exitCode;
3945
}
40-
46+
4147
if (!hasOption(opts, "--threads")) {
4248
const int maxAvailableThreads = static_cast<int>(oneapi::tbb::info::default_concurrency());
4349
int physicalCores = 0;
@@ -93,12 +99,14 @@ int main(int argc, char* argv[]) {
9399
outputBase = deriveOutputBase(filename, outputBase);
94100
spdlog::info("Output base: {}", outputBase);
95101

96-
bool adoptOrphanAtoms = getString(opts, "--adoptOrphanAtoms", "true") == "true";
97-
int minGrainAtomCount = getInt(opts, "--minGrainAtomCount", 100);
98-
bool handleCoherentInterfaces = getString(opts, "--handleCoherentInterfaces", "true") == "true";
99-
bool outputBonds = hasOption(opts, "--outputBonds");
102+
const OptionReader options(descriptor, opts);
103+
104+
bool adoptOrphanAtoms = options.boolean("--adoptOrphanAtoms");
105+
int minGrainAtomCount = options.integer("--minGrainAtomCount");
106+
bool handleCoherentInterfaces = options.boolean("--handleCoherentInterfaces");
107+
bool outputBonds = options.boolean("--outputBonds");
100108

101-
const std::string mergeAlgorithmStr = getString(opts, "--mergeAlgorithm", "GraphClusteringAutomatic");
109+
const std::string mergeAlgorithmStr = options.text("--mergeAlgorithm");
102110
MergeAlgorithm mergeAlgorithm = MergeAlgorithm::GraphClusteringAutomatic;
103111
if(mergeAlgorithmStr == "GraphClusteringManual"){
104112
mergeAlgorithm = MergeAlgorithm::GraphClusteringManual;
@@ -107,7 +115,7 @@ int main(int argc, char* argv[]) {
107115
}else if(mergeAlgorithmStr != "GraphClusteringAutomatic"){
108116
spdlog::warn("Unknown mergeAlgorithm '{}', defaulting to GraphClusteringAutomatic", mergeAlgorithmStr);
109117
}
110-
double mergingThreshold = getDouble(opts, "--mergingThreshold", 0.0f);
118+
double mergingThreshold = options.number("--mergingThreshold");
111119

112120
spdlog::info("Grain segmentation parameters:");
113121
spdlog::info(" - adoptOrphanAtoms: {}", adoptOrphanAtoms);
@@ -118,7 +126,7 @@ int main(int argc, char* argv[]) {
118126
spdlog::info(" - outputBonds: {}", outputBonds);
119127

120128
GrainSegmentationService analyzer;
121-
analyzer.setRMSD(getDouble(opts, "--rmsd", 0.1f));
129+
analyzer.setRMSD(options.number("--rmsd"));
122130
analyzer.setParameters(
123131
adoptOrphanAtoms,
124132
minGrainAtomCount,

0 commit comments

Comments
 (0)