def FromAtomPaths(selfClass, atomPaths, atoms=None): """Create a sequence from a list of atom paths.""" # . Argument check. if (atoms is not None) and (len(atoms) != len(atomPaths)): raise ValueError( "The \"atomPaths\" and \"atoms\" arguments are incompatible.") createAtoms = (atoms is None) # . Initialization. self = selfClass() # . Process the paths. duplicateAtoms = 0 index = 0 for atomPath in atomPaths: (entityLabel, componentLabel, atomLabel) = self.ParsePath(atomPath, labels=3) (entity, component, atom) = self.GetDescendantsFromLabels(entityLabel, componentLabel, atomLabel) if entity is None: entity = SequenceEntity(label=entityLabel) self.AddChild(entity) if component is None: genericLabel = self.ParseLabel(componentLabel, fields=1)[0] component = SequenceComponent(genericLabel=genericLabel, label=componentLabel) entity.AddChild(component) if atom is None: if createAtoms: atom = Atom(index=index, label=atomLabel) else: atom = atoms[index] atom.index = index atom.label = atomLabel index += 1 component.AddChild(atom) else: duplicateAtoms += 1 if duplicateAtoms > 0: raise ValueError( "There were {:d} duplicate atom paths in the sequence.".format( duplicateAtoms)) # . Finish up. return self