Convert reaction entry to YAML dict.
328473
def convert_reaction_entry(self, reaction):
        """"""
        d = OrderedDict()
        d['id'] = reaction.id

        def is_equation_valid(equation):
            # If the equation is a Reaction object, it must have non-zero
            # number of compounds.
            return (equation is not None and (
                    not isinstance(equation, Reaction) or
                    len(equation.compounds) > 0))

        order = {
            key: i for i, key in enumerate(
                ['name', 'genes', 'equation', 'subsystem', 'ec'])}
        prop_keys = (set(reaction.properties) -
                     {'lower_flux', 'upper_flux', 'reversible'})
        for prop in sorted(prop_keys, key=lambda x: (order.get(x, 1000), x)):
            if reaction.properties[prop] is None:
                continue
            d[prop] = reaction.properties[prop]
            if prop == 'equation' and not is_equation_valid(d[prop]):
                del d[prop]

        return d
137219
def _to_dict(self):
        """"""
        _dict = {}
        if hasattr(self, 'key') and self.key is not None:
            _dict['key'] = self.key
        if hasattr(self,
                   'matching_results') and self.matching_results is not None:
            _dict['matching_results'] = self.matching_results
        if hasattr(self, 'event_rate') and self.event_rate is not None:
            _dict['event_rate'] = self.event_rate
        return _dict
240454
def to_yaml(self, skip_nulls=True):
        """"""
        return yaml.safe_dump(self.to_dict(skip_nulls=skip_nulls),
                              default_flow_style=False)
567106
def _convert_reaction(self, reaction):
        if not (reaction['reactants'] or reaction['products'] or reaction['reagents']):
            raise ValueError('empty reaction')
        maps = {'reactants': [], 'products': [], 'reagents': []}
        for i, tmp in maps.items():
            for molecule in reaction[i]:
                used = set()
                for atom in molecule['atoms']:
                    m = atom['mapping']
                    if m:
                        if m in used:
                            if not self._ignore:
                                raise MappingError('mapping in molecules should be unique')
                            warning(f'non-unique mapping in molecule: {m}')
                        else:
                            used.add(m)
                    tmp.append(m)

        length = count(max(max(maps['products'], default=0), max(maps['reactants'], default=0),
                           max(maps['reagents'], default=0)) + 1)

        ''' 
        '''
        for i, tmp in maps.items():
            used = set()
            maps[i] = remap = []
            for m in tmp:
                if not m:
                    remap.append(next(length))
                elif m in used:
                    if not self._ignore:
                        raise MappingError('mapping in reagents or products or reactants should be unique')
                    # force remap non unique atoms in molecules.
                    remap.append(next(length))
                    warning(f'mapping changed: {m} to {remap[-1]}')
                else:
                    remap.append(m)
                    used.add(m)

        if maps['reagents']:
            tmp = (set(maps['reactants']) | set(maps['products'])) & set(maps['reagents'])
            if tmp:
                e = f'reagents has map intersection with reactants or products: {tmp}'
                if not self._ignore:
                    raise MappingError(e)
                warning(e)
                maps['reagents'] = [x if x not in tmp else next(length) for x in maps['reagents']]

        ''' find breaks in map. e.g. 1,2,5,6. 3,4 - skipped
        '''
        if self.__remap:
            lose = sorted(set(range(1, next(length))) - set(maps['reactants']) - set(maps['products']) -
                          set(maps['reagents']), reverse=True)
            if lose:
                for i, tmp in maps.items():
                    if not tmp:
                        continue
                    for j in lose:
                        maps[i] = tmp = [x if x < j else x - 1 for x in tmp]
        ''' end
        '''
        rc = ReactionContainer(meta=reaction['meta'])
        for i, tmp in maps.items():
            shift = 0
            for j in reaction[i]:
                atom_len = len(j['atoms'])
                remapped = {x: y for x, y in enumerate(tmp[shift: atom_len + shift])}
                shift += atom_len
                g = self.__convert_structure(j, remapped)
                rc[i].append(g)
        return rc
267057
def rdf_graph_from_yaml(yaml_root):
    """"""
    G = Graph()
    for top_entry in yaml_root:
        assert len(top_entry) == 1
        node = list(top_entry.keys())[0]
        build_relations(G, node, top_entry[node], None)
    return G
975048
def build_from_yamlstr(cls, yamlstr):
        
        top_dict = yaml.safe_load(yamlstr)
        coordsys = top_dict.pop('coordsys')
        output_list = []
        for e_key, e_dict in sorted(top_dict.items()):
            if e_key == 'coordsys':
                continue
            e_dict = top_dict[e_key]
            e_dict['coordsys'] = coordsys
            output_list += cls.build_from_energy_dict(e_key, e_dict)
        return output_list
778269
def as_dict(self):
        """"""
        attrs = vars(self)
        return {key: attrs[key] for key in attrs if not key.startswith('_')}
706301
def _to_dict(self):
        """"""
        _dict = {}
        if hasattr(self, 'warning_id') and self.warning_id is not None:
            _dict['warning_id'] = self.warning_id
        if hasattr(self, 'message') and self.message is not None:
            _dict['message'] = self.message
        return _dict
1155519
def as_yaml(self):
        
        dumped = dump(self.as_marked_up(), Dumper=StrictYAMLDumper, allow_unicode=True)
        return dumped if sys.version_info[0] == 3 else dumped.decode("utf8")
1322596
def to_nice_yaml(yaml_input, indentation=2):
    
    return yaml.safe_dump(yaml_input, indent=indentation,
                          allow_unicode=True, default_flow_style=False)
883392
def to_dict(self):
        
        d = {
            'model_type': 'regression',
            'name': self.name,
            'fit_filters': self.fit_filters,
            'predict_filters': self.predict_filters,
            'model_expression': self.model_expression,
            'ytransform': YTRANSFORM_MAPPING[self.ytransform],
            'fitted': self.fitted,
            'fit_parameters': None,
            'fit_rsquared': None,
            'fit_rsquared_adj': None
        }

        if self.fitted:
            d['fit_parameters'] = yamlio.frame_to_yaml_safe(
                self.fit_parameters)
            d['fit_rsquared'] = float(self.model_fit.rsquared)
            d['fit_rsquared_adj'] = float(self.model_fit.rsquared_adj)

        return d
1107714
def to_yaml(self):
        """"""
        import yaml

        with self.__reference__.open('w') as fp:
            yaml.dump(self.asjsonld(), fp, default_flow_style=False)
11916
def parse_yaml(self, y):
        ''''''
        super(TargetPort, self).parse_yaml(y)
        self.port_name = y['portName']
        return self
40989
def _to_dict(self):
        """"""
        _dict = {}
        if hasattr(self, 'environment_id') and self.environment_id is not None:
            _dict['environment_id'] = self.environment_id
        if hasattr(self, 'status') and self.status is not None:
            _dict['status'] = self.status
        return _dict
760196
def _to_dict(self):
        """"""
        _dict = {}
        if hasattr(self, 'input') and self.input is not None:
            _dict['input'] = self.input._to_dict()
        if hasattr(self, 'intents') and self.intents is not None:
            _dict['intents'] = [x._to_dict() for x in self.intents]
        if hasattr(self, 'entities') and self.entities is not None:
            _dict['entities'] = [x._to_dict() for x in self.entities]
        return _dict
53143
def to_dict(self):
        ''''''
        d = {'componentId': self.component_id,
                'instanceName': self.instance_name}
        props = []
        for name in self.properties:
            p = {'name': name}
            if self.properties[name]:
                p['value'] = str(self.properties[name])
            props.append(p)
        if props:
            d[RTS_EXT_NS_YAML + 'properties'] = props
        return d
604850
def to_dict(self):
        """"""
        result = {}

        for attr, _ in six.iteritems(self.swagger_types):
            value = getattr(self, attr)
            if isinstance(value, list):
                result[attr] = list(map(
                    lambda x: x.to_dict() if hasattr(x, "to_dict") else x,
                    value
                ))
            elif hasattr(value, "to_dict"):
                result[attr] = value.to_dict()
            elif isinstance(value, dict):
                result[attr] = dict(map(
                    lambda item: (item[0], item[1].to_dict())
                    if hasattr(item[1], "to_dict") else item,
                    value.items()
                ))
            else:
                result[attr] = value
        if issubclass(Payment, dict):
            for key, value in self.items():
                result[key] = value

        return result