Exemplo n.º 1
0
def structure_to_complex(structure: Structure):
    residues = {}
    chains = {}
    for pqr_atom in structure.atoms:
        atom = _Atom._create()
        atom._symbol = pqr_atom.atom_name[:1]
        atom._serial = pqr_atom.atom_number
        atom._name = pqr_atom.atom_name
        atom._position = pqr_atom.position
        atom._is_het = pqr_atom.is_het

        if not pqr_atom.chain_id in chains:
            chain = _Chain._create()
            chain._name = pqr_atom.chain_id
            chains[pqr_atom.chain_id] = chain

        if not pqr_atom.residue_number in residues:
            residue = _Residue._create()
            residue._name = pqr_atom.residue_name
            residue._type = pqr_atom.residue_name
            residue._serial = pqr_atom.residue_number
            residues[pqr_atom.residue_number] = residue
            chains[pqr_atom.chain_id]._add_residue(residue)

        residues[pqr_atom.residue_number]._add_atom(atom)

    mol = _Molecule._create()
    for chain in chains:
        mol._add_chain(chains[chain])

    complex = _Complex._create()
    complex._add_molecule(mol)
    return complex._convert_to_conformers()
Exemplo n.º 2
0
def structure_molecule(model):
    # type: (Content.Model) -> Molecule
    molecule = _Molecule._create()
    molecule._name = model.name

    chain = _Chain._create()
    chain._name = "S"
    molecule._add_chain(chain)
    residue = _Residue._create()
    residue._name = "SDF"
    residue._type = residue._name
    residue.serial = 1
    chain._add_residue(residue)
    atoms_by_serial = {}

    for catom in model.atoms:
        atom = _Atom._create()
        atom._symbol = catom.symbol
        atom._serial = catom.serial
        atom._position = Vector3(catom.x, catom.y, catom.z)
        atom._name = catom.symbol
        atom._is_het = True
        atom._formal_charge = catom.charge
        residue._add_atom(atom)
        atoms_by_serial[atom._serial] = atom
    for cbond in model.bonds:
        if cbond.serial_atom1 in atoms_by_serial and cbond.serial_atom2 in atoms_by_serial:
            bond = _Bond._create()
            bond._atom1 = atoms_by_serial[cbond.serial_atom1]
            bond._atom2 = atoms_by_serial[cbond.serial_atom2]
            bond._kind = enums.Kind.safe_cast(cbond.bond_order)
            residue._add_bond(bond)
    molecule._associated = model._associated
    return molecule
Exemplo n.º 3
0
def structure(content):
    remarks = StructureRemarks(content.remarks)
    complex = _Complex._create()
    complex._remarks = remarks
    # All structured infos
    all_atoms = {}
    all_residues = {}
    all_chains = {}
    all_molecules = {}

    helper = None    
    if content.cell != None:
        helper = UnitCellHelper(content.cell)

    # Read all atoms
    for c_atom in content.atoms:
        chain_name = c_atom.chain
        if c_atom.is_het:
            chain_name = "H" + chain_name

        molecule_id = str(c_atom.model)
        chain_id = molecule_id + ":" + chain_name
        residue_id = chain_id + ":" + str(c_atom.residue_serial)
        atom_id = residue_id + ":" + str(c_atom.atom_serial)
        if not atom_id in all_atoms:
            if not residue_id in all_residues:
                if not chain_id in all_chains:
                    if not molecule_id in all_molecules:
                        molecule = _Molecule._create()
                        molecule._name = str(c_atom.model)
                        all_molecules[molecule_id] = molecule
                        complex._add_molecule(molecule)
                    chain = _Chain._create()
                    chain._name = chain_name
                    all_chains[chain_id] = chain
                    all_molecules[molecule_id]._add_chain(chain)
                residue = _Residue._create()
                residue._name = c_atom.residue_name
                residue._type = residue._name
                residue.serial = c_atom.residue_serial
                all_residues[residue_id] = residue
                all_chains[chain_id]._add_residue(residue)
            atom = StructureAtom(c_atom, helper)
            all_atoms[atom_id] = None
            all_residues[residue_id]._add_atom(atom)
    # Done
    return complex._convert_to_conformers()
Exemplo n.º 4
0
def structure_molecule(atoms, compnds):
    # All structured infos
    all_residues = {}  #<string, Residue>
    all_chains = {}  #<string, Chain>
    all_atoms = {}  #<string, Atom>
    # Read all atoms
    for ratom in atoms:
        atom = _Atom._create()
        atom._symbol = ratom.element_symbol
        atom._serial = ratom.atom_serial_number
        atom._name = ratom.atom_name
        #atom.alts = ratom.atom_alternate_location
        atom._occupancy = ratom.occupancy
        atom._bfactor = ratom.bfactor
        #atom.charge = ratom.atom_charge
        atom._position = Vector3(ratom.atom_x, ratom.atom_y, ratom.atom_z)
        atom._is_het = ratom.is_het_atom
        atom_id = ratom.chain_identifier + ":" + str(
            ratom.residue_serial_number) + ":" + ratom.atom_name + ":" + str(
                ratom.atom_serial_number)
        if not atom_id in all_atoms:
            residue_id = ratom.chain_identifier + ":" + str(
                ratom.residue_serial_number) + ":" + ratom.segment_identifier
            if not residue_id in all_residues:
                residue = _Residue._create()
                residue._name = ratom.residue_name
                residue._type = residue._name
                residue._serial = ratom.residue_serial_number
                # residue.insertion_code = ratom.residue_insertion_code
                all_residues[residue_id] = residue
                chain_id = ratom.chain_identifier
                if ratom.is_het_atom:
                    chain_id = "H" + chain_id
                if not chain_id in all_chains:
                    chain = _Chain._create()
                    chain._name = chain_id
                    all_chains[chain_id] = chain
                all_chains[chain_id]._add_residue(residue)
            all_residues[residue_id]._add_atom(atom)
            all_atoms[atom_id] = atom
    # Final molecule
    molecule = _Molecule._create()
    # Assemble molecule contents
    for chain in all_chains:
        molecule._add_chain(all_chains[chain])
    # Done
    return molecule