コード例 #1
0
ファイル: test_cif.py プロジェクト: materialsproject/pymatgen
    def test_empty(self):
        # single line
        cb = CifBlock.from_string("data_mwe\nloop_\n_tag\n ''")
        self.assertEqual(cb.data['_tag'][0], '')

        # multi line
        cb = CifBlock.from_string("data_mwe\nloop_\n_tag\n;\n;")
        self.assertEqual(cb.data['_tag'][0], '')

        cb2 = CifBlock.from_string(str(cb))
        self.assertEqual(cb, cb2)
コード例 #2
0
ファイル: test_cif.py プロジェクト: materialsproject/pymatgen
    def test_double_quotes_and_underscore_data(self):
        cif_str = """data_test
_symmetry_space_group_name_H-M   "P -3 m 1"
_thing   '_annoying_data'"""
        cb = CifBlock.from_string(cif_str)
        self.assertEqual(cb["_symmetry_space_group_name_H-M"], "P -3 m 1")
        self.assertEqual(cb["_thing"], "_annoying_data")
        self.assertEqual(str(cb), cif_str.replace('"', "'"))
コード例 #3
0
ファイル: test_cif.py プロジェクト: materialsproject/pymatgen
    def test_double_quoted_data(self):
        cif_str = """data_test
_thing   ' '_annoying_data''
_other   " "_more_annoying_data""
_more   ' "even more" ' """
        cb = CifBlock.from_string(cif_str)
        self.assertEqual(cb["_thing"], " '_annoying_data'")
        self.assertEqual(cb["_other"], ' "_more_annoying_data"')
        self.assertEqual(cb["_more"], ' "even more" ')
コード例 #4
0
    def test_double_quoted_data(self):
        cif_str = """data_test
_thing   ' '_annoying_data''
_other   " "_more_annoying_data""
_more   ' "even more" ' """
        cb = CifBlock.from_string(cif_str)
        self.assertEqual(cb["_thing"], " '_annoying_data'")
        self.assertEqual(cb["_other"], ' "_more_annoying_data"')
        self.assertEqual(cb["_more"], ' "even more" ')
コード例 #5
0
    def test_nested_fake_multiline_quotes(self):
        cif_str = """data_test
_thing
;
long quotes
 ;
 still in the quote
 ;
actually going to end now
;"""
        cb = CifBlock.from_string(cif_str)
        self.assertEqual(cb["_thing"], " long quotes  ;  still in the quote"
                                       "  ; actually going to end now")
コード例 #6
0
ファイル: test_cif.py プロジェクト: materialsproject/pymatgen
    def test_nested_fake_multiline_quotes(self):
        cif_str = """data_test
_thing
;
long quotes
 ;
 still in the quote
 ;
actually going to end now
;"""
        cb = CifBlock.from_string(cif_str)
        self.assertEqual(cb["_thing"], " long quotes  ;  still in the quote"
                                       "  ; actually going to end now")
コード例 #7
0
ファイル: test_cif.py プロジェクト: zizai/pymatgen
    def test_to_string(self):
        with open(self.TEST_FILES_DIR / 'Graphite.cif') as f:
            s = f.read()
        c = CifBlock.from_string(s)
        cif_str_2 = str(CifBlock.from_string(str(c)))
        cif_str = """data_53781-ICSD
_database_code_ICSD   53781
_audit_creation_date   2003-04-01
_audit_update_record   2013-02-01
_chemical_name_systematic   Carbon
_chemical_formula_structural   C
_chemical_formula_sum   C1
_chemical_name_structure_type   Graphite(2H)
_chemical_name_mineral   'Graphite 2H'
_exptl_crystal_density_diffrn   2.22
_publ_section_title   'Structure of graphite'
loop_
 _citation_id
 _citation_journal_full
 _citation_year
 _citation_journal_volume
 _citation_page_first
 _citation_page_last
 _citation_journal_id_ASTM
  primary  'Physical Review (1,1893-132,1963/141,1966-188,1969)'
  1917  10  661  696  PHRVAO
loop_
 _publ_author_name
  'Hull, A.W.'
_cell_length_a   2.47
_cell_length_b   2.47
_cell_length_c   6.8
_cell_angle_alpha   90.
_cell_angle_beta   90.
_cell_angle_gamma   120.
_cell_volume   35.93
_cell_formula_units_Z   4
_symmetry_space_group_name_H-M   'P 63/m m c'
_symmetry_Int_Tables_number   194
loop_
 _symmetry_equiv_pos_site_id
 _symmetry_equiv_pos_as_xyz
  1  'x, x-y, -z+1/2'
  2  '-x+y, y, -z+1/2'
  3  '-y, -x, -z+1/2'
  4  '-x+y, -x, -z+1/2'
  5  '-y, x-y, -z+1/2'
  6  'x, y, -z+1/2'
  7  '-x, -x+y, z+1/2'
  8  'x-y, -y, z+1/2'
  9  'y, x, z+1/2'
  10  'x-y, x, z+1/2'
  11  'y, -x+y, z+1/2'
  12  '-x, -y, z+1/2'
  13  '-x, -x+y, -z'
  14  'x-y, -y, -z'
  15  'y, x, -z'
  16  'x-y, x, -z'
  17  'y, -x+y, -z'
  18  '-x, -y, -z'
  19  'x, x-y, z'
  20  '-x+y, y, z'
  21  '-y, -x, z'
  22  '-x+y, -x, z'
  23  '-y, x-y, z'
  24  'x, y, z'
loop_
 _atom_type_symbol
 _atom_type_oxidation_number
  C0+  0
loop_
 _atom_site_label
 _atom_site_type_symbol
 _atom_site_symmetry_multiplicity
 _atom_site_Wyckoff_symbol
 _atom_site_fract_x
 _atom_site_fract_y
 _atom_site_fract_z
 _atom_site_B_iso_or_equiv
 _atom_site_occupancy
 _atom_site_attached_hydrogens
  C1  C0+  2  b  0  0  0.25  .  1.  0
  C2  C0+  2  c  0.3333  0.6667  0.25  .  1.  0"""
        for l1, l2, l3 in zip(
                str(c).split("\n"), cif_str.split("\n"),
                cif_str_2.split("\n")):
            self.assertEqual(l1.strip(), l2.strip())
            self.assertEqual(l2.strip(), l3.strip())
コード例 #8
0
ファイル: test_cif.py プロジェクト: materialsproject/pymatgen
    def test_to_string(self):
        with open(self.TEST_FILES_DIR / 'Graphite.cif') as f:
            s = f.read()
        c = CifBlock.from_string(s)
        cif_str_2 = str(CifBlock.from_string(str(c)))
        cif_str = """data_53781-ICSD
_database_code_ICSD   53781
_audit_creation_date   2003-04-01
_audit_update_record   2013-02-01
_chemical_name_systematic   Carbon
_chemical_formula_structural   C
_chemical_formula_sum   C1
_chemical_name_structure_type   Graphite(2H)
_chemical_name_mineral   'Graphite 2H'
_exptl_crystal_density_diffrn   2.22
_publ_section_title   'Structure of graphite'
loop_
 _citation_id
 _citation_journal_full
 _citation_year
 _citation_journal_volume
 _citation_page_first
 _citation_page_last
 _citation_journal_id_ASTM
  primary  'Physical Review (1,1893-132,1963/141,1966-188,1969)'
  1917  10  661  696  PHRVAO
loop_
 _publ_author_name
  'Hull, A.W.'
_cell_length_a   2.47
_cell_length_b   2.47
_cell_length_c   6.8
_cell_angle_alpha   90.
_cell_angle_beta   90.
_cell_angle_gamma   120.
_cell_volume   35.93
_cell_formula_units_Z   4
_symmetry_space_group_name_H-M   'P 63/m m c'
_symmetry_Int_Tables_number   194
loop_
 _symmetry_equiv_pos_site_id
 _symmetry_equiv_pos_as_xyz
  1  'x, x-y, -z+1/2'
  2  '-x+y, y, -z+1/2'
  3  '-y, -x, -z+1/2'
  4  '-x+y, -x, -z+1/2'
  5  '-y, x-y, -z+1/2'
  6  'x, y, -z+1/2'
  7  '-x, -x+y, z+1/2'
  8  'x-y, -y, z+1/2'
  9  'y, x, z+1/2'
  10  'x-y, x, z+1/2'
  11  'y, -x+y, z+1/2'
  12  '-x, -y, z+1/2'
  13  '-x, -x+y, -z'
  14  'x-y, -y, -z'
  15  'y, x, -z'
  16  'x-y, x, -z'
  17  'y, -x+y, -z'
  18  '-x, -y, -z'
  19  'x, x-y, z'
  20  '-x+y, y, z'
  21  '-y, -x, z'
  22  '-x+y, -x, z'
  23  '-y, x-y, z'
  24  'x, y, z'
loop_
 _atom_type_symbol
 _atom_type_oxidation_number
  C0+  0
loop_
 _atom_site_label
 _atom_site_type_symbol
 _atom_site_symmetry_multiplicity
 _atom_site_Wyckoff_symbol
 _atom_site_fract_x
 _atom_site_fract_y
 _atom_site_fract_z
 _atom_site_B_iso_or_equiv
 _atom_site_occupancy
 _atom_site_attached_hydrogens
  C1  C0+  2  b  0  0  0.25  .  1.  0
  C2  C0+  2  c  0.3333  0.6667  0.25  .  1.  0"""
        for l1, l2, l3 in zip(str(c).split("\n"), cif_str.split("\n"),
                              cif_str_2.split("\n")):
            self.assertEqual(l1.strip(), l2.strip())
            self.assertEqual(l2.strip(), l3.strip())
コード例 #9
0
outputFilePath = str(sys.argv[3])

#loading a poscar object we handle .structure.composition, .structure.formula, and .structure.lattice

#validate the POSCAR that is not well-defined and/or ambiguous.
if Poscar.from_file(inputFileFullPath).true_names:
    ps = Poscar.from_file(inputFileFullPath).structure
#
#casting poscar structure to dict and cif format files
ps_dict = ps.composition.as_dict()
ps_reduced_dict, ps_reduced_factor = ps.composition.get_reduced_formula_and_factor(
)
ps_cif = ps.to("cif")

#cif_sample[0] = "# generated using pymatgen\ndata_Ga2CoS4\n_symmetry_space_group_name_H-M   'P 1'\n_cell_length_a   5.29198729\n_cell_length_b   5.29198728\n_cell_length_c   6.45268046\n_cell_angle_alpha   114.20867693\n_cell_angle_beta   114.20867699\n_cell_angle_gamma   89.99999995\n_symmetry_Int_Tables_number   1\n_chemical_formula_structural   Ga2CoS4\n_chemical_formula_sum   'Ga2 Co1 S4'\n_cell_volume   147.218893696\n_cell_formula_units_Z   1\nloop_\n _symmetry_equiv_pos_site_id\n _symmetry_equiv_pos_as_xyz\n  1  'x, y, z'\nloop_\n _atom_site_type_symbol\n _atom_site_label\n _atom_site_symmetry_multiplicity\n _atom_site_fract_x\n _atom_site_fract_y\n _atom_site_fract_z\n _atom_site_occupancy\n  S  S1  1  0.874869  0.886340  0.253531  1\n  S  S2  1  0.632808  0.125131  0.746469  1\n  S  S3  1  0.113660  0.621337  0.746469  1\n  S  S4  1  0.378663  0.367192  0.253531  1\n  Co  Co5  1  0.000000  0.000000  0.000000  1\n  Ga  Ga6  1  0.500000  0.500000  0.000000  1\n  Ga  Ga7  1  0.250000  0.750000  0.500000  1\n"
cif_sample_from_the_ps_sample_0_structure = CifBlock.from_string(ps_cif).data

## 20170911 battery properties calculation added by Jclee
IS_BATTERY = False
ps_dict_battery_working_ion = dict()
IF_for_working_ion = 0

for keys in ps_dict.keys():
    #if the key is an working ion
    if keys == 'Li' or keys == 'Na' or keys == 'K':
        IS_BATTERY = True
        ps_dict_battery_others = ps_dict.copy()
        ps_dict_battery_working_ion = {keys: ps_dict_battery_others.pop(keys)}
        IF_for_working_ion = 1
    elif keys == 'Mg':  # or keys == 'Ca':
        IS_BATTERY = True