"""Example script demonstrating surface lattice sweep
For more details on the available job types please refer to the Metafold REST API
documentation.
"""
from argparse import ArgumentParser
from functools import partial
from metafold import MetafoldClient
from multiprocessing import Pool
from pprint import pprint
import pandas as pd
import numpy as np
import os
import csv
import numpy as np
from metafold.func_types import JSONEvaluator
from metafold.func import (
CSGIntersect,
EllipsoidPrimitive,
GenerateSamplePoints,
LoadVolume,
Shell,
PointSource,
Redistance,
SampleSurfaceLattice,
SampleSurfaceLattice_Parameters,
SampleVolume,
Threshold,
VolumeAsset,
)
project_id = 5628
access_token = ""
client=MetafoldClient(access_token,project_id)
lattice_types = [
"Gyroid",
"SchwarzD",
"P"
]
threshold = [
-0.7,-0.6,-0.5,-0.4,-0.3,-0.2,-0.1,0,0.1,0.2,0.3,0.4,0.5,0.6,0.7
]
thickness = [ 0.025, 0.05, 0.1]
densities=[]
source = GenerateSamplePoints({"size":[2,2,2] , "offset": [-1,-1,-1], "resolution":[128,128,128]})
for lattice_type in lattice_types:
for threshold_value in threshold:
for thickness_value in thickness:
shape_func = Threshold(
Redistance(
Shell(
Redistance(
SampleSurfaceLattice(
PointSource,
{
"lattice_type": lattice_type,
"scale": [1, 1 , 1],
"threshold": threshold_value,
},
),
{
"thickness": thickness_value,
},
),
),
{
"width": 0.03,
},
)
)
evaluator = JSONEvaluator(source)
shape_func(evaluator)
graph_json=evaluator.json()
job= client.jobs.run("evaluate_metrics", {"graph": graph_json, "point_source": 0})
pprint((lattice_type, threshold_value, thickness_value, job.meta["relative_density"]))
densities.append((lattice_type, threshold_value, thickness_value, job.meta["relative_density"]))
# Convert to DataFrame
df = pd.DataFrame(densities, columns=["lattice_types", "threshold_value", "thickness_value", "relative_density"])
df.to_csv('out.csv', index=False)