예제 #1
0
def patch_swf(target_site, swf_path):
    swf_name = os.path.splitext(os.path.basename(swf_path))[0]

    try:
        abc_index = target_site.PATCH_TARGET_ABC_INDEX
    except AttributeError:
        abc_index = 0

    abc_id = '%s-%d' % (swf_name, abc_index)

    try:
        os.remove(full_path('%s.abc' % abc_id))
        shutil.rmtree(full_path(abc_id))
    except OSError as e:
        if e.errno != errno.ENOENT:
            raise

    run(['abcexport', full_path('%s.swf' % swf_name)])
    run(['rabcdasm', full_path('%s.abc' % abc_id)])
    with cd(full_path(abc_id)):
        run([
            'patch', '-i', os.path.join('..', target_site.PATCH_FILENAME),
            '-p0'])
    run(['rabcasm', full_path('%s/%s.main.asasm' % (abc_id, abc_id))])
    run([
        'abcreplace', full_path('%s.swf' % swf_name), str(abc_index),
        full_path('%s/%s.main.abc' % (abc_id, abc_id))])
예제 #2
0
    def __init__(self, *args, **kwargs):
        swf_path = kwargs['swf_path']
        del kwargs['swf_path']

        self.swf_url = kwargs['swf_url']
        del kwargs['swf_url']

        self.collected_data = kwargs['collected_data']
        del kwargs['collected_data']

        self.target_site = kwargs['target_site']
        del kwargs['target_site']

        self.files_dict = {
            '/proxy.pac': full_path('proxy.pac'),
            self.swf_url: full_path(swf_path),
        }

        super(Handler, self).__init__(*args, **kwargs)
예제 #3
0
파일: test_mol.py 프로젝트: sizmailov/gemmi
    def test_read_1pfe_cif(self):
        st = gemmi.read_structure(full_path('1pfe.cif.gz'))
        self.check_1pfe(st)

        # write structure to cif and read it back
        out_name = get_path_for_tempfile(suffix='.cif')
        st.make_mmcif_document().write_file(out_name)
        st2 = gemmi.read_structure(out_name)
        os.remove(out_name)
        self.check_1pfe(st2)
예제 #4
0
파일: server.py 프로젝트: 5ace/iqiyi-hack
    def __init__(self, *args, **kwargs):
        swf_path = kwargs['swf_path']
        del kwargs['swf_path']

        self.swf_url = kwargs['swf_url']
        del kwargs['swf_url']

        self.collected_data = kwargs['collected_data']
        del kwargs['collected_data']

        self.target_site = kwargs['target_site']
        del kwargs['target_site']

        self.files_dict = {
            '/proxy.pac': full_path('proxy.pac'),
            self.swf_url: full_path(swf_path),
        }

        super(Handler, self).__init__(*args, **kwargs)
예제 #5
0
 def test_ncs(self):
     st = gemmi.read_structure(full_path('5cvz_final.pdb'))
     self.assertEqual(st.resolution, 3.29)
     first_atom = st[0].sole_residue('A', gemmi.SeqId(17, ' '))[0]
     ne2 = st[0].sole_residue('A', gemmi.SeqId('63')).sole_atom('NE2')
     direct_dist = first_atom.pos.dist(ne2.pos)
     self.assertAlmostEqual(direct_dist, 34.89, delta=1e-2)
     nearest_image = st.cell.find_nearest_image(first_atom.pos, ne2.pos)
     nearest_dist = nearest_image.dist()
     self.assertAlmostEqual(nearest_dist, 8.02, delta=1e-2)
예제 #6
0
파일: test_mol.py 프로젝트: Anthchirp/gemmi
 def test_assembly_naming(self):
     st = gemmi.read_structure(full_path('4oz7.pdb'))
     model = st[0]
     a1 = st.assemblies[1]
     bio = a1.make_assembly(model, gemmi.HowToNameCopiedChains.AddNumber)
     self.assertEqual([ch.name for ch in bio], ['B1'])
     bio = a1.make_assembly(model, gemmi.HowToNameCopiedChains.Dup)
     self.assertEqual([ch.name for ch in bio], ['B'])
     bio = a1.make_assembly(model, gemmi.HowToNameCopiedChains.Short)
     self.assertEqual([ch.name for ch in bio], ['B'])
예제 #7
0
파일: test_mol.py 프로젝트: sizmailov/gemmi
 def test_software_category(self):
     doc = gemmi.cif.read_file(full_path('3dg1_final.cif'))
     input_block = doc.sole_block()
     st = gemmi.make_structure_from_block(input_block)
     output_block = st.make_mmcif_document().sole_block()
     software = output_block.get_mmcif_category('_software')
     del software['date']
     assert software['version'][0] is False
     software['version'][0] = None
     self.assertEqual(input_block.get_mmcif_category('_software'), software)
예제 #8
0
 def test_extract_sequence_info(self):
     st = gemmi.read_structure(full_path('5cvz_final.pdb'))
     st.add_entity_types()
     polymer = st[0][0].get_polymer()
     self.assertEqual(polymer.check_polymer_type(),
                      gemmi.PolymerType.PeptideL)
     expected = ('AAATSLVYDTCYVTLTERATTSFQRQSFPTLKGMGDRAFQVVAFTIQGVS'
                 'AAPLMYNARLYNPGDTDSVHATGVQLMGTVPRTVRLTPRVGQNNWFFGNT'
                 'EEAETILAIDGLVSTKGANAPSNTVIVTGCFRLAPSELQSS')
     self.assertEqual(polymer.make_one_letter_sequence(), expected)
예제 #9
0
파일: test_mol.py 프로젝트: mcs07/gemmi
 def test_remove2(self):
     model = gemmi.read_structure(full_path('1pfe.cif.gz'))[0]
     self.assertEqual(len(model), 2)
     del model['A']
     self.assertEqual(len(model), 1)
     b = model['B']
     self.assertEqual(b[0].name, 'DSN')
     del b['1']['DSN']
     self.assertEqual(b[0].name, 'ALA')
     del b[0]
     self.assertEqual(b[0].name, 'N2C')
예제 #10
0
파일: test_mol.py 프로젝트: sizmailov/gemmi
 def test_3dg1(self):
     st = gemmi.read_structure(full_path('3dg1_final.cif'))
     self.assertEqual(st.info['_entry.id'], '3DG1')
     self.assertEqual(len(st[0]), 1)
     chain = st[0]['A']
     for res in chain[-2:]:
         self.assertEqual(res.name, 'HOH')
     for res in chain:
         for atom in res:
             n_images = st.cell.is_special_position(atom.pos)
             self.assertEqual(atom.occ * (n_images + 1), 1.0)
예제 #11
0
파일: test_mol.py 프로젝트: sizmailov/gemmi
 def test_4hhh_frag(self):
     path = full_path('4hhh_frag.pdb')
     with open(path) as f:
         frag = f.read()
     st = gemmi.read_pdb_string(frag)
     in_headers = frag.splitlines()
     out_headers = st.make_pdb_headers().splitlines()
     self.assertEqual(in_headers[0], out_headers[0])
     # the difference 4555 vs 2555 doesn't matter for us
     self.assertEqual(in_headers[1],
                      out_headers[1].replace(' 4555 ', ' 2555 '))
     self.assertEqual(in_headers[2], out_headers[2])
예제 #12
0
 def test_read_write(self):
     path = full_path('5e5z.mtz')
     mtz = gemmi.read_mtz_file(path)
     self.assertEqual(mtz.spacegroup.hm, 'P 1 21 1')
     out_name = get_path_for_tempfile()
     mtz.write_to_file(out_name)
     mtz2 = gemmi.read_mtz_file(out_name)
     os.remove(out_name)
     self.assertEqual(mtz2.spacegroup.hm, 'P 1 21 1')
     if numpy is not None:
         self.assert_numpy_equal(numpy.array(mtz, copy=False), mtz.array)
         self.assert_numpy_equal(mtz.array, mtz2.array)
예제 #13
0
def get_swf():
    print('Downloading the page %s' % PAGE_URL)
    urlh = compat_urllib_request_urlopen(PAGE_URL)
    webpage = urlh.read().decode('utf-8')
    urlh.close()
    mobj = re.search(r'http://[^\'"]+MainPlayer[^.]+\.swf', webpage)
    swf_url = mobj.group(0)
    swf_path = full_path(os.path.basename(swf_url))

    print('SWF URL is %s' % swf_url)

    compat_urllib_request_urlretrieve(swf_url, filename=swf_path)
    return swf_path, swf_url
예제 #14
0
def get_swf():
    print('Downloading the page %s' % PAGE_URL)
    urlh = compat_urllib_request_urlopen(PAGE_URL)
    webpage = urlh.read().decode('utf-8')
    urlh.close()
    mobj = re.search(r'http://[^\'"]+MainPlayer[^.]+\.swf', webpage)
    swf_url = mobj.group(0)
    swf_path = full_path(os.path.basename(swf_url))

    print('SWF URL is %s' % swf_url)

    compat_urllib_request_urlretrieve(swf_url, filename=swf_path)
    return swf_path, swf_url
예제 #15
0
 def test_ignore_flag(self):
     st = gemmi.read_structure(full_path('4oz7.pdb'))
     st.setup_entities()
     ns = gemmi.NeighborSearch(st[0], st.cell, 5).populate()
     cs = gemmi.ContactSearch(4.0)
     cs.ignore = gemmi.ContactSearch.Ignore.SameResidue
     results = cs.find_contacts(ns)
     self.assertEqual(len(results), 607)
     cs.ignore = gemmi.ContactSearch.Ignore.SameChain
     results = cs.find_contacts(ns)
     self.assertEqual(len(results), 190)
     self.assertTrue(
         all(r.image_idx != 0 or r.partner1.chain is not r.partner2.chain
             for r in results))
예제 #16
0
    def test_reading(self):
        m = gemmi.read_ccp4_map(full_path('5i55_tiny.ccp4'))
        self.assertEqual(m.grid.nu, 8)
        self.assertEqual(m.grid.nv, 6)
        self.assertEqual(m.grid.nw, 10)
        self.assertEqual(m.header_i32(28), 0)
        m.set_header_i32(28, 20140)  # set NVERSION
        self.assertEqual(m.header_i32(28), 20140)
        dmax = m.header_float(21)
        self.assertEqual(dmax, max(p.value for p in m.grid))
        self.assertNotEqual(m.grid.axis_order, gemmi.AxisOrder.XYZ)
        m.setup()
        self.assertEqual(m.grid.axis_order, gemmi.AxisOrder.XYZ)
        self.assertEqual(m.grid.nu, 60)
        self.assertEqual(m.grid.nv, 24)
        self.assertEqual(m.grid.nw, 60)
        self.assertEqual(m.grid.point_count, 60 * 24 * 60)
        self.assertEqual(m.header_float(14), 90.0)  # 14 - alpha angle
        self.assertEqual(m.grid.unit_cell.alpha, 90.0)
        self.assertEqual(m.grid.spacegroup.ccp4, 4)  # P21

        pos = gemmi.Position(19.4, 3., 21.)
        frac = m.grid.unit_cell.fractionalize(pos)
        pos_value = 2.1543798446655273
        self.assertAlmostEqual(m.grid.interpolate_value(pos), pos_value)
        self.assertAlmostEqual(m.grid.interpolate_value(frac), pos_value)

        # this spacegroup has symop -x, y+1/2, -z
        m.grid.set_value(60 - 3, 24 // 2 + 4, 60 - 5,
                         100)  # image of (3, 4, 5)
        self.assertEqual(m.grid.get_value(60 - 3, 24 // 2 + 4, 60 - 5), 100)
        self.assertTrue(math.isnan(m.grid.get_value(3, 4, 5)))
        m.grid.symmetrize_max()
        self.assertEqual(m.grid.get_value(3, 4, 5), 100)
        m.grid.set_value(3, 4, 5, float('nan'))
        self.assertTrue(math.isnan(m.grid.get_value(3, 4, 5)))
        m.grid.symmetrize_min()
        self.assertEqual(m.grid.get_value(3, 4, 5), 100)
        m.grid.set_value(60 - 3, 24 // 2 + 4, 60 - 5, float('nan'))
        m.grid.symmetrize_max()
        self.assertEqual(m.grid.get_value(60 - 3, 24 // 2 + 4, 60 - 5), 100)
        if numpy:
            arr = numpy.array(m.grid, copy=False)
            self.assertEqual(arr.shape, (60, 24, 60))
            self.assertEqual(arr[3][4][5], 100)
            grid2 = gemmi.FloatGrid(arr)
            self.assertTrue(
                numpy.allclose(m.grid, grid2, atol=0.0, rtol=0,
                               equal_nan=True))
예제 #17
0
def get_swf(target_site):
    swf_url = target_site.get_site_swf()
    parts = compat_urlparse.urlparse(swf_url)
    swf_path = full_path(os.path.basename(parts.path))
    urlh = compat_urllib_request.urlopen(swf_url)
    with open(swf_path, 'wb') as f:
        f.write(urlh.read())

    if hasattr(target_site, 'decrypt_swf'):
        old_swf_path = swf_path
        swf_path = os.path.splitext(swf_path)[0] + '_decrypted.swf'
        decrypted_swf = target_site.decrypt_swf(read_file(old_swf_path))
        write_file(swf_path, decrypted_swf)

    return swf_path, swf_url
예제 #18
0
def get_swf(target_site):
    swf_url = target_site.get_site_swf()
    parts = compat_urlparse.urlparse(swf_url)
    swf_path = full_path(os.path.basename(parts.path))
    urlh = compat_urllib_request.urlopen(swf_url)
    with open(swf_path, 'wb') as f:
        f.write(urlh.read())

    if hasattr(target_site, 'decrypt_swf'):
        old_swf_path = swf_path
        swf_path = os.path.splitext(swf_path)[0] + '_decrypted.swf'
        decrypted_swf = target_site.decrypt_swf(read_file(old_swf_path))
        write_file(swf_path, decrypted_swf)

    return swf_path, swf_url
예제 #19
0
    def test_scaling(self):
        doc = gemmi.cif.read(full_path('r5wkdsf.ent'))
        rblock = gemmi.as_refln_blocks(doc)[0]
        fobs_data = rblock.get_value_sigma('F_meas_au', 'F_meas_sigma_au')
        if numpy:
            self.assertEqual(fobs_data.value_array.shape, (367, ))

        # without mask
        fc_data = rblock.get_f_phi('F_calc_au', 'phase_calc')
        scaling = gemmi.Scaling(fc_data.unit_cell, fc_data.spacegroup)
        scaling.prepare_points(fc_data, fobs_data)
        scaling.fit_isotropic_b_approximately()
        scaling.fit_parameters()
        #print(scaling.k_overall, scaling.b_overall)
        scaling.scale_data(fc_data)
예제 #20
0
파일: server.py 프로젝트: nsdown/iqiyi-hack
    def __init__(self, *args, **kwargs):
        self.swf_path = kwargs['swf_path']
        del kwargs['swf_path']

        self.collected_data = kwargs['collected_data']
        del kwargs['collected_data']

        files = [self.swf_path, '/proxy.pac']

        self.files_dict = {
            filename: full_path(os.path.basename(filename))
            for filename in files
        }

        super(Handler, self).__init__(*args, **kwargs)
예제 #21
0
    def __init__(self, *args, **kwargs):
        self.swf_path = kwargs['swf_path']
        del kwargs['swf_path']

        self.collected_data = kwargs['collected_data']
        del kwargs['collected_data']

        files = [self.swf_path, '/proxy.pac']

        self.files_dict = {
            filename: full_path(os.path.basename(filename))
            for filename in files
        }

        super(Handler, self).__init__(*args, **kwargs)
예제 #22
0
    def test_ncs(self):
        st = gemmi.read_structure(full_path('5cvz_final.pdb'))
        self.assertEqual(st.resolution, 3.29)
        first_atom = st[0].sole_residue('A', gemmi.SeqId(17, ' '))[0]
        ne2 = st[0].sole_residue('A', gemmi.SeqId('63')).sole_atom('NE2')
        direct_dist = first_atom.pos.dist(ne2.pos)
        self.assertAlmostEqual(direct_dist, 34.89, delta=1e-2)
        nearest_image = st.cell.find_nearest_image(first_atom.pos, ne2.pos)
        nearest_dist = nearest_image.dist()
        self.assertAlmostEqual(nearest_dist, 8.02, delta=1e-2)

        # test __getitem__(splice) - unrelated to NCS (sometimes we put
        # unrelated tests together to avoid the same file again)
        chain = st[0]['A']
        res = chain.next_residue(chain[:5][0])
        self.assertTrue(res is chain[1])
예제 #23
0
 def test_superposition(self):
     model = gemmi.read_structure(full_path('4oz7.pdb'))[0]
     poly1 = model['A'].get_polymer()
     poly2 = model['B'].get_polymer()
     ptype = poly1.check_polymer_type()
     S = gemmi.SupSelect
     s1 = gemmi.calculate_superposition(poly1, poly2, ptype, S.CaP)
     s2 = gemmi.calculate_superposition(poly1, poly2, ptype, S.MainChain)
     s3 = gemmi.calculate_superposition(poly1, poly2, ptype, S.All)
     self.assertEqual(s1.count, 10)
     self.assertEqual(s2.count, 39)
     self.assertEqual(s3.count, 77)
     self.assertAlmostEqual(s1.rmsd, 0.146, places=3)
     self.assertAlmostEqual(s2.rmsd, 0.174, places=3)
     self.assertAlmostEqual(s3.rmsd, 0.400, places=3)
     for s in [s1, s2, s3]:
         self.assertAlmostEqual(s.transform.vec.y, 17.0, places=1)
예제 #24
0
파일: test_mol.py 프로젝트: sizmailov/gemmi
 def test_rnase_predefined_removals(self, add_entities=False):
     st = gemmi.read_structure(full_path('rnase_frag.pdb'))
     if add_entities:
         self.assertEqual(len(st.entities), 0)
         st.assign_subchains()
         st.ensure_entities()
         self.assertEqual(len(st.entities), 4)
     model = st[0]
     nres_a = len(model['A'])
     nres_b = len(model['B'])
     st.remove_ligands_and_waters()  # removes SO4 from each chain
     self.assertEqual(len(model['A']), nres_a - 1)
     self.assertEqual(len(model['B']), nres_b - 1)
     self.assertEqual(len(model['W']), 0)
     self.assertEqual(len(model), 3)
     st.remove_empty_chains()
     self.assertEqual(len(model), 2)
예제 #25
0
    def test_f_phi_grid(self):
        path = full_path('5wkd_phases.mtz.gz')
        mtz = gemmi.read_mtz_file(path)
        size = mtz.get_size_for_hkl()
        for half_l in (False, True):
            grid1 = mtz.get_f_phi_on_grid('FWT', 'PHWT', size, half_l=half_l)
            grid2 = mtz.get_f_phi_on_grid('FWT',
                                          'PHWT',
                                          size,
                                          half_l=half_l,
                                          order=gemmi.AxisOrder.ZYX)
            if numpy is None:
                continue
            array1 = numpy.array(grid1, copy=False)
            array2 = numpy.array(grid2, copy=False)
            self.assertTrue((array2 == array1.transpose(2, 1, 0)).all())

        fft_test(self, mtz, 'FWT', 'PHWT', size)
예제 #26
0
파일: test_mol.py 프로젝트: sizmailov/gemmi
 def test_previous_next_residue(self):
     st = gemmi.read_structure(full_path('1pfe.cif.gz'),
                               merge_chain_parts=False)
     chain_b = st[0]['B']
     res = chain_b['6']['ALA']
     res = chain_b.next_residue(res)
     self.assertEqual(res.name, 'NCY')
     res = chain_b.next_residue(res)
     self.assertEqual(res.name, 'MVA')
     self.assertIsNone(chain_b.next_residue(res))
     res = chain_b.previous_residue(res)
     self.assertEqual(res.name, 'NCY')
     res = chain_b.previous_residue(res)
     self.assertEqual(res.name, 'ALA')
     res = chain_b.next_residue(chain_b['7']['N2C'])
     self.assertEqual(res.name, 'MVA')
     self.assertEqual(chain_b.previous_residue(res).name, 'NCY')
     self.assertIsNone(chain_b.previous_residue(chain_b[0]))
예제 #27
0
def patch_swf(swf_path):
    swf_name = os.path.splitext(os.path.basename(swf_path))[0]
    abc_index = 0
    abc_id = '%s-%d' % (swf_name, abc_index)

    try:
        os.remove(full_path('%s.abc' % abc_id))
        shutil.rmtree(full_path(abc_id))
    except OSError as e:
        if e.errno != errno.ENOENT:
            raise

    run(['abcexport', full_path('%s.swf' % swf_name)])
    run(['rabcdasm', full_path('%s.abc' % abc_id)])
    subprocess.Popen([
        'patch', '-p0', '-i', '../asasm.patch'], cwd=full_path(abc_id)).wait()
    run(['rabcasm', full_path('%s/%s.main.asasm' % (abc_id, abc_id))])
    run([
        'abcreplace', full_path('%s.swf' % swf_name), str(abc_index),
        full_path('%s/%s.main.abc' % (abc_id, abc_id))])
예제 #28
0
 def test_remove_and_add_column(self):
     path = full_path('5e5z.mtz')
     col_name = 'FREE'
     mtz = gemmi.read_mtz_file(path)
     col = mtz.column_with_label(col_name)
     col_idx = col.idx
     ncol = len(mtz.columns)
     if numpy is None:
         return
     self.assert_numpy_equal(col.array, numpy.array(col, copy=False))
     arr = col.array.copy()
     mtz_data = numpy.array(mtz, copy=True)
     self.assertEqual(mtz_data.shape, (mtz.nreflections, ncol))
     mtz.remove_column(col_idx)
     self.assertEqual(len(mtz.columns), ncol - 1)
     self.assertEqual(
         numpy.array(mtz, copy=False).shape, (mtz.nreflections, ncol - 1))
     col = mtz.add_column(col_name, 'I', dataset_id=0, pos=col_idx)
     numpy.array(col, copy=False)[:] = arr
     self.assert_numpy_equal(mtz_data, numpy.array(mtz, copy=False))
예제 #29
0
 def test_read_write_5cvz_final(self, via_cif=False):
     path = full_path('5cvz_final.pdb')
     with open(path) as f:
         expected = [line.rstrip() for line in f
                     if is_written_to_pdb(line, via_cif)
                     # SCALE is not written b/c CRYST1 has more precision.
                     and line[:5] != 'SCALE']
     st = gemmi.read_structure(path)
     if via_cif:
         # input file w/o TER record -> subchains not setup automatically
         st.setup_entities()
         doc = st.make_mmcif_document()
         st = gemmi.make_structure_from_block(doc[0])
     out_lines = self.write_and_read(st, via_cif=False)
     if via_cif:
         out_lines = [line for line in out_lines
                      # input file has no REMARK 2, but it gets generated
                      # from REMARK 3 when going pdb->cif->pdb
                      if line[:10] != 'REMARK   2'
                      and line[:5] != 'TER  ']
     self.assertEqual(expected, [line.rstrip() for line in out_lines])
예제 #30
0
    def test_remove2(self):
        model = gemmi.read_structure(full_path('1pfe.cif.gz'))[0]
        self.assertEqual(len(model), 2)
        del model['A']
        self.assertEqual(len(model), 1)
        b = model['B']
        self.assertEqual(b[0].name, 'DSN')
        del b['1']['DSN']
        self.assertEqual(b[0].name, 'ALA')
        del b[0]
        self.assertEqual(b[0].name, 'N2C')

        # test append_residues()
        self.assertEqual(len(b), 20)
        b.append_residues(b[:5], min_sep=10)
        self.assertEqual(len(b), 25)

        # test append_residues() with empty chain
        new_chain = gemmi.Chain('X')
        new_chain.append_residues(b[:5], min_sep=1)
        self.assertEqual(len(new_chain), 5)
예제 #31
0
def patch_swf(swf_path):
    swf_name = os.path.splitext(os.path.basename(swf_path))[0]
    abc_index = 0
    abc_id = '%s-%d' % (swf_name, abc_index)

    try:
        os.remove(full_path('%s.abc' % abc_id))
        shutil.rmtree(full_path(abc_id))
    except OSError as e:
        if e.errno != errno.ENOENT:
            raise

    run(['abcexport', full_path('%s.swf' % swf_name)])
    run(['rabcdasm', full_path('%s.abc' % abc_id)])
    subprocess.Popen(['patch', '-p0', '-i', '../asasm.patch'],
                     cwd=full_path(abc_id)).wait()
    run(['rabcasm', full_path('%s/%s.main.asasm' % (abc_id, abc_id))])
    run([
        'abcreplace',
        full_path('%s.swf' % swf_name),
        str(abc_index),
        full_path('%s/%s.main.abc' % (abc_id, abc_id))
    ])
예제 #32
0
 def test_read_1orc(self):
     st = gemmi.read_structure(full_path('1orc.pdb'))
     self.assertEqual(st.resolution, 1.54)
     self.assertAlmostEqual(st.cell.a, 34.77)
     self.assertEqual(st.cell.alpha, 90)
     self.assertEqual(len(st.ncs), 0)
     model = st[0]
     self.assertEqual(len(model), 1)
     self.assertEqual(len(model.subchains()), 2)
     A = model['A']
     waters = A.get_waters()
     self.assertEqual(len(waters), 57)  # FORMUL   2  HOH   *57(H2 O)
     self.assertTrue(all(res.name == 'HOH' for res in waters))
     self.assertTrue(A['3'])
     self.assertFalse(A['0'])
     self.assertEqual([res.seqid.num for res in A if res.seqid.icode != ' '],
                      [56] * 5)
     self.assertEqual(len(A['55']), 1)
     self.assertEqual(len(A['55B']), 0)
     self.assertEqual(len(A['56B']), 1)
     self.assertEqual(A['56'][0].seqid.icode, ' ')
     self.assertEqual(A['56c'][0].seqid.icode, 'C')
예제 #33
0
파일: test_mol.py 프로젝트: Anthchirp/gemmi
    def test_assembly(self):
        st = gemmi.read_structure(full_path('1pfe.cif.gz'),
                                  merge_chain_parts=False)
        model = st[0]
        self.assertEqual([ch.name for ch in model],
                         ['A', 'B', 'A', 'B', 'A', 'B'])
        a_mass = sum(ch.calculate_mass() for ch in model if ch.name == 'A')
        b_mass = sum(ch.calculate_mass() for ch in model if ch.name == 'B')
        model_mass = model.calculate_mass()
        self.assertAlmostEqual(model_mass, a_mass + b_mass)

        self.assertEqual(len(st.assemblies), 1)
        asem = st.assemblies[0]
        bio = asem.make_assembly(model, gemmi.HowToNameCopiedChains.Short)
        self.assertEqual([ch.name for ch in bio], ['A', 'B', 'C', 'D'])
        self.assertAlmostEqual(bio.calculate_mass(), 2 * model_mass)
        self.assertAlmostEqual(bio[0].calculate_mass(), a_mass)
        self.assertAlmostEqual(bio[1].calculate_mass(), b_mass)
        self.assertAlmostEqual(bio[2].calculate_mass(), a_mass)
        self.assertAlmostEqual(bio[3].calculate_mass(), b_mass)

        bio = asem.make_assembly(model, gemmi.HowToNameCopiedChains.AddNumber)
        self.assertEqual([ch.name for ch in bio], ['A1', 'B1', 'A2', 'B2'])
예제 #34
0
def main():
    args = docopt(__doc__)

    config_filename = common.full_path(args['<configfile>'])
    yaml_config = common.read_config_file(config_filename)
    configs = load_nginx_config_table(yaml_config)
    template_mgr = common.get_template_mgr_for_location('templates')
    config_template = template_mgr.get_template('nginx_config.j2')

    # show all the configurations
    #
    if args['-l'] or args['--list']:
        for key in configs.keys():
            print(configs[key])

        exit(0)

    # we can generate without a specific nginx config, iff there's just one
    #
    output = None
    config_name = args['--env']

    if args['<configfile>'] and not config_name:
        if len(configs.keys()) > 1:
            print('Multiple configurations found. Please specify one.')
            exit(0)
        output = config_template.render(nginx_config=configs.values()[0])

    else:
        if not configs.get(config_name):
            print('No nginx configuration labeled "%s" in %s.' %
                  (config_name, config_filename))
            exit(0)
        output = config_template.render(nginx_config=configs[config_name])

    print(output)
    exit(0)
예제 #35
0
파일: ngen.py 프로젝트: binarymachines/snap
def main():
    args = docopt(__doc__)

    config_filename = common.full_path(args['<configfile>'])
    yaml_config = common.read_config_file(config_filename)
    configs = load_nginx_config_table(yaml_config)
    template_mgr = common.get_template_mgr_for_location('templates')
    config_template = template_mgr.get_template('nginx_config.j2')

    # show all the configurations
    #
    if args['-l'] or args['--list']:        
        for key in configs.keys():
            print configs[key]

        exit(0)
        
    # we can generate without a specific nginx config, iff there's just one
    #
    output = None
    config_name = args['--env']

    if args['<configfile>'] and not config_name:
        if len(configs.keys()) > 1:
            print 'Multiple configurations found. Please specify one.'
            exit(0)        
        output = config_template.render(nginx_config=configs.values()[0])
        
    else:
        if not configs.get(config_name):
            print 'No nginx configuration labeled "%s" in %s.' % (config_name, config_filename)
            exit(0)
        output = config_template.render(nginx_config=configs[config_name])
        
    print output
    exit(0)
예제 #36
0
파일: test_mol.py 프로젝트: sizmailov/gemmi
 def test_5i55_predefined_removals(self, clear_entities=False):
     st = gemmi.read_structure(full_path('5i55.cif'))
     if clear_entities:
         self.assertEqual(len(st.entities), 4)
         st.entities = gemmi.EntityList()
         self.assertEqual(len(st.entities), 0)
     lys12 = st[0]['A']['12']['LYS']
     count_b = sum(a.altloc == 'B' for a in lys12)
     model = st[0]
     # one author-chain and 4 label-chains: AA, 2 x ligand, waters
     self.assertEqual(len(model), 1)
     self.assertEqual(len(model.subchains()), 4)
     n_waters = len(model.get_subchain('D'))
     n_sites = model.count_atom_sites()
     occ_sum = model.count_occupancies()
     self.assertEqual(n_sites, occ_sum + count_b)
     st.remove_waters()
     self.assertEqual(len(model.subchains()), 3)
     self.assertEqual(model.count_atom_sites(), n_sites - n_waters)
     self.assertEqual(model.count_occupancies(), occ_sum - n_waters)
     st.remove_empty_chains()
     self.assertEqual(len(model.subchains()), 3)
     n_res = len(model['A'])
     st.remove_ligands_and_waters()
     self.assertEqual(len(model['A']), n_res - 2)
     mse = model['A'][0]
     self.assertEqual(len(mse), 8)
     mse.trim_to_alanine()
     self.assertEqual([a.name for a in mse], ['N', 'CA', 'C', 'O', 'CB'])
     model['A'].trim_to_alanine()
     # ALA has 5 atoms, except the last one which has OXT (hence +1)
     expected_count = sum(4 + (r.name != 'GLY') for r in model['A']) + 1
     self.assertEqual(model.count_occupancies(), expected_count)
     st.remove_alternative_conformations()
     self.assertEqual(model.count_occupancies(), expected_count - 5 / 2.)
     self.assertTrue(not any(a.has_altloc() for a in lys12))
예제 #37
0
파일: test_mol.py 프로젝트: sizmailov/gemmi
    def test_remove2(self):
        st = gemmi.read_structure(full_path('1pfe.cif.gz'))
        model = st[0]
        self.assertEqual(len(model), 2)
        b = model['B']
        self.assertEqual(b[0].name, 'DSN')
        del b['1']['DSN']
        self.assertEqual(b[0].name, 'ALA')
        del b[0]
        self.assertEqual(b[0].name, 'N2C')

        # test append_residues()
        self.assertEqual(len(b), 20)
        b.append_residues(b[:5], min_sep=10)
        self.assertEqual(len(b), 25)

        # test append_residues() with empty chain
        new_chain = gemmi.Chain('X')
        new_chain.append_residues(b[:5], min_sep=1)
        self.assertEqual(len(new_chain), 5)

        # test adding and removing chains
        model.add_chain(new_chain, unique_name=False)
        model.add_chain(new_chain, unique_name=True)
        model.add_chain(new_chain)
        self.assertEqual([chain.name for chain in model], list('ABXCX'))
        del model[2:]
        model.add_chain(new_chain, unique_name=True)
        self.assertEqual([chain.name for chain in model], list('ABX'))
        del model[-1]
        del model['A']
        self.assertEqual(len(model), 1)
        self.assertEqual(model[0].name, 'B')
        doc = st.make_mmcif_document()
        ref_seq = doc[0].get_mmcif_category('_struct_ref_seq')
        self.assertEqual(ref_seq['pdbx_strand_id'], ['B'])