def to_structured_from_spec(self, spec: Spec) -> 'State': if not spec.is_structured: return self if not self.first.is_structured and self.first.to_component_spec() == spec.to_non_struct_spec().to_component_spec(): return InteractionState(self.first.with_struct_from_spec(spec), self.second) elif not self.second.is_structured and self.second.to_component_spec() == spec.to_non_struct_spec().to_component_spec(): return InteractionState(self.first, self.second.with_struct_from_spec(spec)) else: return self
def to_structured_from_spec(self, spec: Spec) -> 'State': if self.first.to_non_struct_spec().to_component_spec( ) == spec.to_non_struct_spec().to_component_spec(): assert self.second.to_non_struct_spec().to_component_spec( ) == spec.to_non_struct_spec().to_component_spec() return SelfInteractionState( self.first.with_struct_from_spec(spec), self.second.with_struct_from_spec(spec)) else: return self
def get_node_id(specification: Spec, node_type: Union[NodeType, LocusResolution]) -> str: """ Building the respective node_id Args: specification: Specification of an elemental state node_type: type of the node to get the proper ID Returns: The string ID of the node corresponding to asked conditions. Raises: AssertionError if non of the conditions are fulfilled. """ if node_type in [NodeType.component, LocusResolution.component]: return str(specification.to_component_spec()) if node_type in [NodeType.domain, LocusResolution.domain] and specification.locus.domain: return '{0}_[{1}]'.format(specification.name, specification.locus.domain) if node_type in [NodeType.residue, LocusResolution.residue] and specification.locus.residue: return str(specification) raise AssertionError
def states_for_component(self, component: Spec) -> List[State]: """Returns all the States that live on a certain Component.""" assert component.is_component_spec return [ x for x in self.states if component.to_non_struct_spec() in x.components ]
def to_structured_from_spec(self, spec: Spec) -> 'State': if self.spec.to_non_struct_spec().to_component_spec( ) == spec.to_non_struct_spec().to_component_spec( ) and spec.is_structured: return ModificationState(self.spec.with_struct_from_spec(spec), self.modifier) else: return self
def complement_states_for_component(self, component: Spec, state: State) -> List[State]: if not state.is_structured: for group in self.states_for_component_grouped(component).values(): if state in group: return [x for x in group if x != state] else: complements = self.complement_states_for_component( component.to_non_struct_spec(), state.to_non_structured()) return [x.to_structured_from_state(state) for x in complements]
def complement_states_for_component(self, component: Spec, state: State) -> List[State]: """Returns all States mutually exclusive with the State given that live on the Component given.""" if not state.is_structured: for group in self.states_for_component_grouped(component).values(): if state in group: return [x for x in group if x != state] raise AssertionError else: # The structure information is first thrown away to determine the mutually exclusive # states, and then applied again (as far as possible). complements = self.complement_states_for_component( component.to_non_struct_spec(), state.to_non_structured()) return [x.to_structured_from_state(state) for x in complements]
def states_for_component(self, component: Spec) -> List[State]: assert component.is_component_spec return [ x for x in self.states if component.to_non_struct_spec() in x.components ]
def to_structured_from_spec(self, spec: Spec) -> 'State': if spec.is_structured and self.spec.to_non_struct_spec( ).to_component_spec() == spec.to_non_struct_spec().to_component_spec(): return EmptyBindingState(self.spec.with_struct_from_spec(spec)) else: return self
def set_mod(self, spec: Spec, mod: StateModifier) -> None: self._mol_builders[spec.to_component_spec()].set_mod(spec, mod)
def set_half_bond(self, spec: Spec, value: Optional[int]) -> None: self._mol_builders[spec.to_component_spec()].set_bond_index( spec, value)
def add_mol(self, spec: Spec, is_reactant: bool = False) -> None: if spec.to_component_spec() not in self._mol_builders: self._mol_builders[spec.to_component_spec()] = MolBuilder( spec.to_component_spec(), is_reactant)
def __init__(self, spec: Spec, is_reactant: bool = False) -> None: self.name = str(spec.to_non_struct_spec()) self.site_to_mod = {} # type: Dict[str, str] self.site_to_bond = {} # type: Dict[str, Optional[int]] self.is_reactant = is_reactant
def __init__(self, spec: Spec) -> None: self.spec = spec self.name = str(spec.to_non_struct_spec()) # type: str self.site_defs = {} # type: Dict[str, List[str]]