def from_structure(structure):
try:<EOL><INDENT>from Bio import PDB<EOL>if isinstance(structure, str):<EOL><INDENT>p = PDB.PDBParser()<EOL>structure = p.get_structure('<STR_LIT:S>', structure)<EOL><DEDENT>if isinstance(structure, PDB.Structure.Structure):<EOL><INDENT>for _ in structure.get_chains():<EOL><INDENT>atoms = [np.array(atom.get_coord())<EOL>for atom in structure.get_atoms()]<EOL><DEDENT><DEDENT><DEDENT>except ImportError:<EOL><INDENT>print("<STR_LIT>")<EOL>raise<EOL><DEDENT>atoms = np.array(structure)<EOL>try:<EOL><INDENT>import scipy<EOL>D = scipy.spatial.distance.pdist(atoms, '<STR_LIT>')<EOL>D = scipy.spatial.distance.squareform(D)<EOL><DEDENT>except ImportError:<EOL><INDENT>print("<STR_LIT>")<EOL>raise<EOL><DEDENT>m = np.max(<NUM_LIT:1> / D[D != <NUM_LIT:0>])<EOL>M = np.zeros(D.shape)<EOL>M[D != <NUM_LIT:0>] = <NUM_LIT:1> / D[D != <NUM_LIT:0>]<EOL>M[D == <NUM_LIT:0>] = m<EOL>return M<EOL>
Return contact data from a 3D structure (in pdb format).