コード例 #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))
コード例 #2
0
 def test_get_scatlen(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]
     real, imag = sld.get_scatlen('C3', array)
     assert_almost_equal(real, 3.0e-5)
     assert_almost_equal(imag, 2.0e-5)
     return
コード例 #3
0
ファイル: test_readwrite.py プロジェクト: arm61/falass
 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
コード例 #4
0
 def test_get_scatlen_fail(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]
     with self.assertRaises(ValueError) as context:
         sld.get_scatlen('C4', array)
     self.assertTrue(
         "Attempt to get the scattering length of the atom type {} failed. This should never "
         "happen. Please contact the developers".format('C4') in str(
             context.exception))
     return
コード例 #5
0
ファイル: readwrite.py プロジェクト: arm61/falass
    def read_lgt(self):
        """Parses .lgt.

        Parses the lgtfile. 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.lgtfile:
            lines = line_count(self.lgtfile)
            print("Reading LGT file")
            percentage = 0
            print_update(percentage)
            file = open(self.lgtfile, 'r')
            for i, line in enumerate(file):
                percentage_new = np.floor(i / lines * 100)
                percentage = check_update(percentage, percentage_new)
                line_list = line.split()
                duplicate = check_duplicates(self.scat_lens, line_list[0])
                if not duplicate:
                    i = 1
                    if self.xray:
                        i *= 2.817940
                    self.scat_lens.append(
                        dataformat.ScatLens(line_list[0],
                                            float(line_list[1]) * i,
                                            float(line_list[2]) * i))
            print_update(100)
            file.close()
        else:
            raise ValueError("No lgtfile has been defined.")
        return
コード例 #6
0
 def test_scatlens(self):
     a = dataformat.ScatLens('C1', 1., 0.)
     assert_equal(a.atom, 'C1')
     assert_equal(a.real, 1.0e-5)
     assert_equal(a.imag, 0.0)