MoleFraction

class openff.evaluator.substances.MoleFraction(value=UNDEFINED)[source]

The mole fraction of a Component in a Substance.

__init__(value=UNDEFINED)
Parameters

value (float or int) – The value of this amount.

Methods

__init__([value])

param value

The value of this amount.

from_json(file_path)

Create this object from a JSON file.

get_attributes([attribute_type])

Returns all attributes of a specific attribute_type.

json([file_path, format])

Creates a JSON representation of this class.

parse_json(string_contents)

Parses a typed json string into the corresponding class structure.

to_number_of_molecules(total_substance_molecules)

Converts this amount to an exact number of molecules

validate([attribute_type])

Validate the values of the attributes.

Attributes

identifier

A string identifier for this amount.

value

The value of this amount.

value

The value of this amount. The default value of this attribute is not set and must be set by the user..

Type

float

property identifier

A string identifier for this amount.

to_number_of_molecules(total_substance_molecules, tolerance=None)[source]

Converts this amount to an exact number of molecules

Parameters
  • total_substance_molecules (int) – The total number of molecules in the whole substance. This amount will contribute to a portion of this total number.

  • tolerance (float, optional) – The tolerance with which this amount should be in. As an example, when converting a mole fraction into a number of molecules, the total number of molecules may not be sufficiently large enough to reproduce this amount.

Returns

The number of molecules which this amount represents, given the total_substance_molecules.

Return type

int

validate(attribute_type=None)[source]

Validate the values of the attributes. If attribute_type is set, only attributes of that type will be validated.

Parameters

attribute_type (type of Attribute, optional) – The type of attribute to validate.

Raises

ValueError or AssertionError

classmethod from_json(file_path)

Create this object from a JSON file.

Parameters

file_path (str) – The path to load the JSON from.

Returns

The parsed class.

Return type

cls

classmethod get_attributes(attribute_type=None)

Returns all attributes of a specific attribute_type.

Parameters

attribute_type (type of Attribute, optional) – The type of attribute to search for.

Returns

The names of the attributes of the specified type.

Return type

list of str

json(file_path=None, format=False)

Creates a JSON representation of this class.

Parameters
  • file_path (str, optional) – The (optional) file path to save the JSON file to.

  • format (bool) – Whether to format the JSON or not.

Returns

The JSON representation of this class.

Return type

str

classmethod parse_json(string_contents)

Parses a typed json string into the corresponding class structure.

Parameters

string_contents (str or bytes) – The typed json string.

Returns

The parsed class.

Return type

Any