Skip to content

Commit

Permalink
better checking for class types based on attrs
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-dudt committed Feb 7, 2024
1 parent 8f1d3fd commit ac0fc14
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions desc/objectives/getters.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,20 +223,26 @@ def _is_any_instance(things, cls):
return any([isinstance(t, cls) for t in things])

# Equilibrium
if hasattr(thing, "_Rb_lmn") and hasattr(thing, "_Zb_lmn"):
if (
hasattr(thing, "Ra_n")
and hasattr(thing, "Za_n")
and hasattr(thing, "Rb_lmn")
and hasattr(thing, "Zb_lmn")
and hasattr(thing, "L_lmn")
):
if not _is_any_instance(constraints, AxisRSelfConsistency):
constraints += (AxisRSelfConsistency(eq=thing),)
if not _is_any_instance(constraints, AxisZSelfConsistency):
constraints += (AxisZSelfConsistency(eq=thing),)
if not _is_any_instance(constraints, BoundaryRSelfConsistency):
constraints += (BoundaryRSelfConsistency(eq=thing),)
if not _is_any_instance(constraints, BoundaryZSelfConsistency):
constraints += (BoundaryZSelfConsistency(eq=thing),)
if not _is_any_instance(constraints, FixLambdaGauge):
constraints += (FixLambdaGauge(eq=thing),)
if not _is_any_instance(constraints, AxisRSelfConsistency):
constraints += (AxisRSelfConsistency(eq=thing),)
if not _is_any_instance(constraints, AxisZSelfConsistency):
constraints += (AxisZSelfConsistency(eq=thing),)

# Curve
elif hasattr(thing, "_shift") and hasattr(thing, "_rotmat"):
elif hasattr(thing, "shift") and hasattr(thing, "rotmat"):
if not _is_any_instance(constraints, FixCurveShift):
constraints += (FixCurveShift(curve=thing),)
if not _is_any_instance(constraints, FixCurveRotation):
Expand Down

0 comments on commit ac0fc14

Please sign in to comment.