Exemplo n.º 1
0
    def set_lgts(self):
        """Assign scattering lengths.

        Assigned the scattering lengths from the lgtfile to the different atom types. If no lgtfile is defined falass
        will help the user to build one by working through the atom types in the pdb file and requesting input of the
        real and imaginary scattering lengths. This will also occur if a atom type if found in the pdbfile but not in
        the given lgts file. falass will write the lgtfile to disk if atom types do not feature in the given lgtfile or
        one is written from scratch.
        """
        if self.files.lgtfile:
            lines = len(self.files.atoms)
            print("Setting atoms lengths")
            percentage = 0
            readwrite.print_update(percentage)
            path, extension = os.path.splitext(self.files.lgtfile)
            lgtfile_name = path + extension
            for i in range(0, len(self.files.atoms)):
                percentage_new = np.floor(i / lines * 100)
                percentage = readwrite.check_update(percentage, percentage_new)
                for j in range(0, len(self.files.atoms[i])):
                    duplicate = readwrite.check_duplicates(self.files.scat_lens, self.files.atoms[i][j].atom)
                    if not duplicate:
                        self.new_file = True
                        real_scat_len = input('The following atom type has no scattering length given '
                                              'in the lgt file {} \nPlease define a real scattering length for '
                                              'this atom type: '.format(self.files.atoms[i][j].atom))
                        imag_scat_len = input('\nPlease define a imaginary scattering length for '
                                              'this atom type: '.format(self.files.atoms[i][j].atom))
                        self.files.scat_lens.append(dataformat.ScatLens(self.files.atoms[i][j].atom, float(real_scat_len),
                                                                  float(imag_scat_len)))
            readwrite.print_update(100)
        else:
            self.new_file = True
            print('There was no lgt file defined, falass will help you define one and save it for future use.')
            for i in range(0, len(self.files.atoms)):
                for j in range(0, len(self.files.atoms[i])):
                    duplicate = readwrite.check_duplicates(self.files.scat_lens, self.files.atoms[i][j].atom)
                    if not duplicate:
                        real_scat_len = input('The following atom type has no scattering length given '
                                              'in the lgt file {} \nPlease define a real scattering length for '
                                              'this atom type: '.format(self.files.atoms[i][j].atom))
                        imag_scat_len = input('\nPlease define a imaginary scattering length for '
                                              'this atom type: '.format(self.files.atoms[i][j].atom))
                        self.files.scat_lens.append(dataformat.ScatLens(self.files.atoms[i][j].atom, float(real_scat_len),
                                                                  float(imag_scat_len)))
            lgtfile_name = input("What should the lgt file be named? ")
            path, extension = os.path.splitext(lgtfile_name)
            if extension != '.lgt':
                lgtfile_name = path + '.lgt'
        if self.new_file:
            i = 0
            while os.path.isfile(lgtfile_name):
                i+=1
                lgtfile_name = path + '_' + str(i) + '.lgt'

            lgtsf = open(lgtfile_name, 'w')
            for i in range(0, len(self.files.scat_lens)):
                lgtsf.write('{} {} {}\n'.format(self.files.scat_lens[i].atom, self.files.scat_lens[i].real * 1e5,
                                                self.files.scat_lens[i].imag * 1e5))
            print('A new lgtfile has been written with the name {}'.format(lgtfile_name))
Exemplo n.º 2
0
 def test_check_duplicates_false(self):
     atom1 = dataformat.ScatLens('C1', 1.0, 0.0)
     atom2 = dataformat.ScatLens('C2', 2.0, 1.0)
     atom3 = dataformat.ScatLens('C3', 3.0, 2.0)
     array = [atom1, atom2, atom3]
     check = dataformat.ScatLens('C4', 4.0, 3.0)
     bool_ret = readwrite.check_duplicates(array, check.atom)
     assert_equal(bool_ret, False)
     return