示例#1
0
 def run(self):
     if checkfile(self.filepath)[0] and checkfile(self.filepath)[1] == 1:
         self.singFile = True
         if self.connect_to_server():
             self.filefinder = FileFinder(self)
             self.filefinder.recycle = False
             self.filefinder.list_flie(self.filepath)
     elif checkfile(self.filepath)[0] and checkfile(self.filepath)[1] == 0:
         self.singFile = False
         self.findfileOver = False
         if self.connect_to_server():
             print(dict('cd') + os.path.basename(self.filepath))
             self.commandThread.send_command(
                 COMMANE_FILE_INFO + divider_arg +
                 os.path.basename(self.filepath) + divider_arg + '-1' +
                 divider_arg + str(msg_index))
             while self.waitingCreateDir:
                 time.sleep(0.1)
             self.waitingCreateDir = True
             self.filefinder = FileFinder(self)
             self.filefinder.recycle = False
             self.filefinder.list_flie(self.filepath)
             self.findfileOver = True
     elif not checkfile(self.filepath)[0]:
         print(dict('picf'))
示例#2
0
 def run(self):
     if checkfile(self.filepath)[0] and checkfile(self.filepath)[1] == 1: # 文件
         self.singFile = True
         if self.connect_to_server():
             self.filefinder = FileFinder(self)
             self.filefinder.recycle = False
             self.filefinder.list_flie(self.filepath)
     elif checkfile(self.filepath)[0] and checkfile(self.filepath)[1] == 0: # 目录
         self.singFile = False
         self.findfileOver = False
         if self.connect_to_server():
             print('创建文件夹' + os.path.basename(self.filepath))
             self.commandThread.send_command(COMMANE_FILE_INFO + divider_arg+
                                             os.path.basename(self.filepath) + divider_arg +
                                             '-1' +divider_arg
                                             + str(msg_index))
             while self.waitingCreateDir:  #等待服务端(接收端的目录创建完成)
                 time.sleep(0.1)
             self.waitingCreateDir = True
             self.filefinder = FileFinder(self)
             self.filefinder.recycle = False
             self.filefinder.list_flie(self.filepath)  # 主体的循环,调用OnFindDir,OnFindFile
             self.findfileOver = True  # 结束传输
     elif not checkfile(self.filepath)[0]:
         print('请输入正确的文件路径')
示例#3
0
def parse_PDB(pdb_file):

    u.checkfile(pdb_file)

    atom_names = []
    res_names = []
    res_ids = []
    atom_coord = []

    with open(pdb_file) as f:

        for line in f:

            # Read Atoms
            if line[0:4] == 'ATOM' or line[0:6] == 'HETATM':

                atom_names.append(line[12:15])
                res_names.append(line[17:19])

                try:
                    res_ids.append(int(line[22:25]))

                except ValueError:
                    res_ids.append(None)

                x = float(line[30:37])
                y = float(line[38:45])
                z = float(line[46:53])
                atom_coord.append([x, y, z])

    return atom_coord
示例#4
0
def keyInSavePath():
    while True:
        filepath = input(dict('pidp'))
        if checkfile(filepath)[0] and checkfile(filepath)[1] == 0:
            return filepath, True
        elif not checkfile(filepath)[0]:
            warning(dict('pde'))
        elif checkfile(filepath)[0] and checkfile(filepath)[1] == 1:
            warning(dict('dpif'))
示例#5
0
def keyInSavePath():
    '''
    输入存储的文件加路径
    '''
    while True:
        filepath = input('请输入文件夹路径')
        if checkfile(filepath)[0] and checkfile(filepath)[1] == 0:
            return filepath, True
        elif not checkfile(filepath)[0]:
            warning('该路径下不存在任何文件')
        elif checkfile(filepath)[0] and checkfile(filepath)[1] == 1:
            warning('这个路径指向一个文件')
示例#6
0
def keyInFilePath():
    while True:
        filepath = input('请输入文件或者文件夹的路径:')
        if filepath.endswith(dir_divider()):
            filepath2 = filepath[:len(filepath)-1]
        else:
            filepath2 = filepath
        if checkfile(filepath2)[0]:
            return filepath2, True
        else:
            print('该路径下不存在任何东西')
示例#7
0
def keyInFilePath():
    while True:
        filepath = input(dict('pif'))
        if filepath.endswith(dir_divider()):
            filepath2 = filepath[:len(filepath) - 1]
        else:
            filepath2 = filepath
        if checkfile(filepath2)[0]:
            return filepath2, True
        else:
            print(dict('pde'))
示例#8
0
def parse_MOL2(mol2_file):

    u.checkfile(mol2_file)

    atom_names = []
    atom_types = []
    res_names = []
    res_ids = []
    atom_coord = []

    with open(mol2_file) as f:

        while True:

            line = f.readline()

            if not line:
                break

            # Read initial lines
            if line[0:17] == '@<TRIPOS>MOLECULE':
                f.readline()
                info = f.readline().split()
                NAtoms = int(info[0])
                try:
                    NRes = int(info[2])
                except:
                    NRes = 1

            # Read Atoms
            elif  line[0:13] == '@<TRIPOS>ATOM':
                for i in range(NAtoms):

                    data = f.readline().split()
                    
                    # save data for the old one
                    atom_names.append(data[1])
                    atom_types.append(data[5])
                    atom_coord.append(map(float, data[2:5]))
                    
    return atom_coord
示例#9
0
    filepath_ok = True
    port_ok = True
    host_ok = False
    if args.port and args.port > 0 :
        port = args.port
        if port == default_command_socket_port:
            warning('%s %d %s,%s' % ('端口',default_command_socket_port,'不可用','请输入其他的数字'))
            port , port_ok = keyInPort()
    elif args.port and args.port <=0:
        warning('端口号必须为正整数')
        port, port_ok = keyInPort()

    filepath = args.filepath
    if not filepath:
        filepath , filepath_ok = keyInFilePath()
    elif not checkfile(args.filepath)[0]:
        warning('该路径下不存在任何文件')
        filepath , filepath_ok = keyInFilePath()

    host = args.host
    if not host:
        host , host_ok = keyInHost()
    else:
        host_ok = True

    if port_ok and filepath_ok and host_ok:
        findercallback = MyfinderCallback()
        if not checkfile(filepath)[1]:
           print('%s %s' % ('在此查找文件:',filepath))
        FileFinder_Fast(findercallback).list_flie(filepath)
        global sumsize
示例#10
0
                        '--host',
                        required=False,
                        help=(dict('thtp')),
                        type=str)

    args = parser.parse_args()

    port = default_data_socket_port
    port_ok = True
    host_ok = False
    save_path_ok = False

    save_path = args.dir
    if not save_path:
        save_path = 'downloads'
        if checkfile(save_path)[0] and checkfile(save_path)[1] == 0:
            if not os.path.exists(save_path): os.makedirs(save_path)
        save_path_ok = True
    else:
        if not checkfile(save_path)[0]:
            warning(dict('pde'))
            save_path, save_path_ok = keyInSavePath()
        else:
            save_path_ok = True

    if args.host:
        host = args.host
        host_ok = True
    else:
        host = '0.0.0.0'
        host_ok = True
示例#11
0
def parse_input(infile):
    '''Returns a Dictionary with dipole types,
    and a list of tuples for points of application of the dipoles.
    The keys of dipole types dictionary are the flags set ny the user in the input.
    Each value is a tuple. The first element of the tuple is a list containing the
    Dipolar Strength, the Excitation energy and the damping. The second element of
    the tuple is a flag defining the type of polarizability to calculate (electric or
    magnetic). The third element of the tuple if present only for magnetic polarizabilities
    and it is the bj coefficient.

    For application points, the data are tuples of 3 elements.
    Each tuple contains, as first element, the center expressed in terms
    of atom indexes and, as second element, the weight to be applied on the
    first element of the list. As third element, we have a list of dipoles to be applied
    in that point. The dipole is described through a list containing the dipole
    type and its orientation, in terms of atomic indexes.'''

    u.checkfile(infile)

    type_counter = 0
    center_counter = 0

    dipole_types = {}
    centers = []

    with open(infile) as f:

        while True:

            line = f.readline()

            if not line:
                break

            if line.strip():

                if line.startswith('#'):
                    continue
                
                # Create Dipole Types Dictionary
                elif line.split()[0].lower() == 'type':
                    
                    type_counter += 1
                    type_flag = line.split()[1]

                    # Try to read TYPE definition without optional keyword
                    try:
                        dipole = map(float, line.split()[2:])
                        pol_type = 'ele'
                        dipole_types[type_flag] = (map(float, line.split()[2:]), pol_type)

                    # Read TYPE definition with optional keyword
                    except ValueError:
                        pol_type = line.split()[-2]
                        bj = float(line.split()[-1])
                        dipole_types[type_flag] = (map(float, line.split()[2:-2]), pol_type, bj)

                    type_counter += 1
    
                # Centers
                elif line.split()[0].lower() == 'center':
    
                    center_counter += 1
                    weight = float(line.split()[1])
                    atom_idx = u.extend_compact_list(line.split()[2:])

                    # Adjust indices to Python's numeration
                    atom_idx = map(lambda x: x - 1, atom_idx)

                    data = f.readline().strip()

                    # Retrieve dipoles applied in this center
                    dipoles = []
                    while True:

                        if not data or data.split()[0].lower() != 'dipole':
                            break 
                        
                        data = data.split()
                        dip_type = [data[1]]
                        dip_ori = data[2:]
                        
                        if len(dip_ori) == 2:
                            dip_ori = u.extend_compact_list(dip_ori)

                        elif len(dip_ori) > 2:
                            theta = float(dip_ori[-1])
                            dip_ori = u.extend_compact_list(dip_ori[:-1])
                            dip_ori = dip_ori + [theta]


                        dipole = dip_type + dip_ori
                        dipoles.append(dipole)

                        data = f.readline().strip()

                    centers.append((atom_idx, weight, dipoles))

                # Dipoles
                elif line.split()[0].lower() == 'dipole':
    
                    if center_counter == 0:
                        print(u.banner(text='ERROR', ch='#', length=80))
                        print
                        print(" You defined a DIPOLE before assigning it a CENTER in %s" % infile)
                        print
                        sys.exit()
    
                    # dipole_counter += 1
    
    if type_counter == 0:
        print(u.banner(text='ERROR', ch='#', length=80))
        print
        print(" No dipole TYPE has been defined in %s" % infile)
        print
        sys.exit()


    return dipole_types, centers
示例#12
0
def parse_XYZ(xyz_file):

    u.checkfile(xyz_file)
    struct = np.loadtxt(xyz_file, skiprows=2, usecols=[1, 2, 3])

    return struct.tolist()