Skip to content

Commit

Permalink
Update _components.py
Browse files Browse the repository at this point in the history
  • Loading branch information
BenGillen1998 committed Jan 24, 2025
1 parent e45b7b4 commit 66dc03b
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions qsdsan/_components.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,13 +151,13 @@ def extend(self, components):
for component in components: self.append(component)


def compile(self, skip_checks=False):
def compile(self, skip_checks=False, ignore_inaccurate_molar_weight=False):
'''Cast as a :class:`CompiledComponents` object.'''
components = tuple(self)
tmo._chemicals.prepare(components, skip_checks)
setattr(self, '__class__', CompiledComponents)

try: self._compile(components)
try: self._compile(components, ignore_inaccurate_molar_weight)
except Exception as error:
setattr(self, '__class__', Components)
setattr(self, '__dict__', {i.ID: i for i in components})
Expand Down Expand Up @@ -616,13 +616,15 @@ def compile(self, skip_checks=False):
pass


def _compile(self, components):
def _compile(self, components, ignore_inaccurate_molar_weight):
dct = self.__dict__
tuple_ = tuple # this speeds up the code
components = tuple_(dct.values())
CompiledChemicals._compile(self, components)
for component in components:
missing_properties = component.get_missing_properties(_key_component_properties)
if (ignore_inaccurate_molar_weight == False) and (component.measured_as != None):
raise RuntimeError(f'{component} does not have a sensible molar weight. Set ignore_inaccurate_molar_weight=True to bypass this error.')
if not missing_properties: continue
missing = utils.repr_listed_values(missing_properties)
raise RuntimeError(f'{component} is missing key component-related properties ({missing}).')
Expand Down

0 comments on commit 66dc03b

Please sign in to comment.