@@ -550,142 +550,150 @@ class local_compound_factory_impl : public compound_factory_impl
550
550
for (const auto &[id, name, threeLetterCode, group] :
551
551
file[" comp_list" ][" chem_comp" ].rows <std::string, std::string, std::string, std::string>(" id" , " name" , " three_letter_code" , " group" ))
552
552
{
553
- // if (std::regex_match(group, peptideRx))
554
- // mKnownPeptides.insert(threeLetterCode);
555
- // else if (cif::iequals(group, "DNA") or cif::iequals(group, "RNA"))
556
- // mKnownBases.insert(threeLetterCode);
557
-
558
- // Test if this compound is known in CCD
559
553
auto &rdb = m_local_file[" comp_" + id];
560
554
if (rdb.empty ())
561
555
{
562
556
std::cerr << " Missing data in restraint file for id " + id + ' \n ' ;
563
557
continue ;
564
558
}
565
559
566
- cif::datablock db (id);
560
+ construct_compound (rdb, id, name, threeLetterCode, group);
561
+ }
562
+ }
567
563
568
- float formula_weight = 0 ;
569
- int formal_charge = 0 ;
570
- std::map<std::string,size_t > formula_data;
564
+ compound *create (const std::string &id) override ;
571
565
572
- for (size_t ord = 1 ; const auto &[atom_id, type_symbol, type, charge, x, y, z] :
573
- rdb[" chem_comp_atom" ].rows <std::string, std::string, std::string, int , float , float , float >(
574
- " atom_id" , " type_symbol" , " type" , " charge" , " x" , " y" , " z" ))
575
- {
576
- auto atom = cif::atom_type_traits (type_symbol);
577
- formula_weight += atom.weight ();
578
-
579
- formula_data[type_symbol] += 1 ;
580
-
581
- db[" chem_comp_atom" ].emplace ({
582
- { " comp_id" , id },
583
- { " atom_id" , atom_id },
584
- { " type_symbol" , type_symbol },
585
- { " charge" , charge },
586
- { " model_Cartn_x" , x, 3 },
587
- { " model_Cartn_y" , y, 3 },
588
- { " model_Cartn_z" , z, 3 },
589
- { " pdbx_ordinal" , ord++ }
590
- });
591
-
592
- formal_charge += charge;
593
- }
566
+ private:
594
567
595
- for (size_t ord = 1 ; const auto &[atom_id_1, atom_id_2, type, aromatic] :
596
- rdb[" chem_comp_bond" ].rows <std::string, std::string, std::string, bool >(" atom_id_1" , " atom_id_2" , " type" , " aromatic" ))
597
- {
598
- std::string value_order (" SING" );
599
-
600
- if (cif::iequals (type, " single" ) or cif::iequals (type, " sing" ))
601
- value_order = " SING" ;
602
- else if (cif::iequals (type, " double" ) or cif::iequals (type, " doub" ))
603
- value_order = " DOUB" ;
604
- else if (cif::iequals (type, " triple" ) or cif::iequals (type, " trip" ))
605
- value_order = " TRIP" ;
606
-
607
- db[" chem_comp_bond" ].emplace ({
608
- { " comp_id" , id },
609
- { " atom_id_1" , atom_id_1 },
610
- { " atom_id_2" , atom_id_2 },
611
- { " value_order" , value_order },
612
- { " pdbx_aromatic_flag" , aromatic },
613
- // TODO: fetch stereo_config info from chem_comp_chir
614
- { " pdbx_ordinal" , ord++ }
615
- });
616
- }
568
+ compound *construct_compound (const datablock &db, const std::string &id, const std::string &name, const std::string &three_letter_code, const std::string &group);
617
569
618
- db.emplace_back (rdb[" pdbx_chem_comp_descriptor" ]);
570
+ cif::file m_local_file;
571
+ };
619
572
620
- std::string formula;
621
- for (bool first = true ; const auto &[symbol, count]: formula_data)
573
+ compound *local_compound_factory_impl::create (const std::string &id)
574
+ {
575
+ compound *result = nullptr ;
576
+
577
+ for (auto &db : m_local_file)
578
+ {
579
+ if (db.name () == " comp_" + id)
580
+ {
581
+ auto chem_comp = db.get (" chem_comp" );
582
+ if (not chem_comp)
583
+ break ;
584
+
585
+ try
622
586
{
623
- if (std::exchange (first, false ))
624
- formula += ' ' ;
625
- formula += symbol;
626
- if (count > 1 )
627
- formula += std::to_string (count);
587
+ const auto &[id, name, threeLetterCode, group] =
588
+ chem_comp->front ().get <std::string, std::string, std::string, std::string>(" id" , " name" , " three_letter_code" , " group" );
589
+
590
+ result = construct_compound (db, id, name, threeLetterCode, group);
591
+ }
592
+ catch (const std::exception &ex)
593
+ {
594
+ std::throw_with_nested (std::runtime_error (" Error loading compound " + id));
628
595
}
629
596
630
- std::string type;
631
- if (cif::iequals (group, " peptide" ) or cif::iequals (group, " l-peptide" ) or cif::iequals (group, " l-peptide linking" ))
632
- type = " L-PEPTIDE LINKING" ;
633
- else if (cif::iequals (group, " dna" ))
634
- type = " DNA LINKING" ;
635
- else if (cif::iequals (group, " rna" ))
636
- type = " RNA LINKING" ;
637
- else
638
- type = " NON-POLYMER" ;
639
-
640
- db[" chem_comp" ].emplace ({
641
- { " id" , id },
642
- { " name" , name },
643
- { " type" , type },
644
- { " formula" , formula },
645
- { " pdbx_formal_charge" , formal_charge },
646
- { " formula_weight" , formula_weight },
647
- { " three_letter_code" , threeLetterCode }
648
- });
649
-
650
- m_compounds.push_back (new compound (db));
597
+ break ;
651
598
}
652
599
}
653
600
654
- // compound *create(const std::string &id) override;
601
+ return result;
602
+ }
655
603
656
- private:
657
- cif::file m_local_file;
658
- };
604
+ compound *local_compound_factory_impl::construct_compound (const datablock &rdb, const std::string &id,
605
+ const std::string &name, const std::string &three_letter_code, const std::string &group)
606
+ {
607
+ cif::datablock db (id);
659
608
660
- // compound *local_compound_factory_impl::create(const std::string &id)
661
- // {
662
- // compound *result = nullptr ;
609
+ float formula_weight = 0 ;
610
+ int formal_charge = 0 ;
611
+ std::map<std::string, size_t > formula_data ;
663
612
664
- // for (auto &db : m_local_file)
665
- // {
666
- // if (db.name() == id)
667
- // {
668
- // cif::datablock db_copy(db);
613
+ for (size_t ord = 1 ; const auto &[atom_id, type_symbol, type, charge, x, y, z] :
614
+ rdb[" chem_comp_atom" ].rows <std::string, std::string, std::string, int , float , float , float >(
615
+ " atom_id" , " type_symbol" , " type" , " charge" , " x" , " y" , " z" ))
616
+ {
617
+ auto atom = cif::atom_type_traits (type_symbol);
618
+ formula_weight += atom.weight ();
669
619
670
- // try
671
- // {
672
- // result = new compound(db_copy, 1);
673
- // }
674
- // catch (const std::exception &ex)
675
- // {
676
- // std::throw_with_nested(std::runtime_error("Error loading compound " + id));
677
- // }
620
+ formula_data[type_symbol] += 1 ;
678
621
622
+ db[" chem_comp_atom" ].emplace ({
623
+ { " comp_id" , id },
624
+ { " atom_id" , atom_id },
625
+ { " type_symbol" , type_symbol },
626
+ { " charge" , charge },
627
+ { " model_Cartn_x" , x, 3 },
628
+ { " model_Cartn_y" , y, 3 },
629
+ { " model_Cartn_z" , z, 3 },
630
+ { " pdbx_ordinal" , ord++ }
631
+ });
679
632
680
- // std::shared_lock lock(mMutex);
681
- // m_compounds.push_back(result);
633
+ formal_charge += charge;
634
+ }
635
+
636
+ for (size_t ord = 1 ; const auto &[atom_id_1, atom_id_2, type, aromatic] :
637
+ rdb[" chem_comp_bond" ].rows <std::string, std::string, std::string, bool >(" atom_id_1" , " atom_id_2" , " type" , " aromatic" ))
638
+ {
639
+ std::string value_order (" SING" );
682
640
683
- // break;
684
- // }
685
- // }
641
+ if (cif::iequals (type, " single" ) or cif::iequals (type, " sing" ))
642
+ value_order = " SING" ;
643
+ else if (cif::iequals (type, " double" ) or cif::iequals (type, " doub" ))
644
+ value_order = " DOUB" ;
645
+ else if (cif::iequals (type, " triple" ) or cif::iequals (type, " trip" ))
646
+ value_order = " TRIP" ;
686
647
687
- // return result;
688
- // }
648
+ db[" chem_comp_bond" ].emplace ({
649
+ { " comp_id" , id },
650
+ { " atom_id_1" , atom_id_1 },
651
+ { " atom_id_2" , atom_id_2 },
652
+ { " value_order" , value_order },
653
+ { " pdbx_aromatic_flag" , aromatic },
654
+ // TODO: fetch stereo_config info from chem_comp_chir
655
+ { " pdbx_ordinal" , ord++ }
656
+ });
657
+ }
658
+
659
+ db.emplace_back (rdb[" pdbx_chem_comp_descriptor" ]);
660
+
661
+ std::string formula;
662
+ for (bool first = true ; const auto &[symbol, count]: formula_data)
663
+ {
664
+ if (std::exchange (first, false ))
665
+ formula += ' ' ;
666
+ formula += symbol;
667
+ if (count > 1 )
668
+ formula += std::to_string (count);
669
+ }
670
+
671
+ std::string type;
672
+ if (cif::iequals (group, " peptide" ) or cif::iequals (group, " l-peptide" ) or cif::iequals (group, " l-peptide linking" ))
673
+ type = " L-PEPTIDE LINKING" ;
674
+ else if (cif::iequals (group, " dna" ))
675
+ type = " DNA LINKING" ;
676
+ else if (cif::iequals (group, " rna" ))
677
+ type = " RNA LINKING" ;
678
+ else
679
+ type = " NON-POLYMER" ;
680
+
681
+ db[" chem_comp" ].emplace ({
682
+ { " id" , id },
683
+ { " name" , name },
684
+ { " type" , type },
685
+ { " formula" , formula },
686
+ { " pdbx_formal_charge" , formal_charge },
687
+ { " formula_weight" , formula_weight },
688
+ { " three_letter_code" , three_letter_code }
689
+ });
690
+
691
+ std::shared_lock lock (mMutex );
692
+
693
+ auto result = new compound (db);
694
+ m_compounds.push_back (result);
695
+ return result;
696
+ }
689
697
690
698
// --------------------------------------------------------------------
691
699
0 commit comments