BALL 1.5.0
Loading...
Searching...
No Matches
assignBondOrderProcessor.h
Go to the documentation of this file.
1// -*- Mode: C++; tab-width: 2; -*-
2// vi: set ts=2:
3//
4
5#ifndef BALL_STRUCTURE_ASSIGNBONDORDERPROCESSOR_H
6#define BALL_STRUCTURE_ASSIGNBONDORDERPROCESSOR_H
7
8#ifndef BALL_CONCEPT_PROCESSOR_H
10#endif
11
12#ifndef BALL_KERNEL_ATOMCONTAINER_H
14#endif
15
16#ifndef BALL_DATATYPE_HASHMAP_H
18#endif
19
20#ifndef BALL_DATATYPE_HASHSET_H
22#endif
23
24#ifndef BALL_KERNEL_BOND_H
25 #include <BALL/KERNEL/bond.h>
26#endif
27
28#ifndef BALL_DATATYPE_OPTIONS_H
30#endif
31
32#ifndef BALL_COMMON_EXCEPTION_H
34#endif
35
36#ifndef BALL_SYSTEM_TIMER_H
37# include <BALL/SYSTEM/timer.h>
38#endif
39
40#ifndef BALL_STRUCTURE_BONDORDERS_BONDORDERASSIGNMENTSTRATEGY_H
42#endif
43
44#ifndef BALL_STRUCTURE_BONDORDERS_BONDORDERASSIGNMENT_H
46#endif
47
48#ifndef BALL_STRUCTURE_BONDORDERS_PARTIALBONDORDERASSIGNMENT_H
50#endif
51
52#include <map>
53#include <vector>
54
55namespace BALL
56{
89 : public UnaryProcessor<AtomContainer>
90 {
91 protected:
93 friend class BondOrderAssignment;
94
95 class PQ_Entry_;
96 friend class PQ_Entry_;
97
99
105
106 public:
107
113 {
118
124
130
140 static const char* OVERWRITE_SELECTED_BONDS;
141
146 static const char* ADD_HYDROGENS; //TODO
147
152 static const char* COMPUTE_ALSO_CONNECTIVITY; //TODO
153
158 static const char* CONNECTIVITY_CUTOFF; //TODO
159
162 static const char* USE_FINE_PENALTY;
163
166 static const char* KEKULIZE_RINGS;
167
170 static const char* ALGORITHM;
171
174 static const char* INIFile;
175
178 static const char* MAX_BOND_ORDER;
179
188 static const char* MAX_NUMBER_OF_SOLUTIONS;
189
200 static const char* MAX_PENALTY;
201
212
218 static const char* BOND_LENGTH_WEIGHTING;
219
224 static const char* APPLY_FIRST_SOLUTION;
225
226 };
227
230 {
234 static const bool OVERWRITE_SELECTED_BONDS;
235 static const bool ADD_HYDROGENS;
236 static const bool COMPUTE_ALSO_CONNECTIVITY;
237 static const float CONNECTIVITY_CUTOFF;
238 static const bool USE_FINE_PENALTY;
239 static const bool KEKULIZE_RINGS;
240 static const String ALGORITHM;
241 static const String INIFile;
242 static const int MAX_BOND_ORDER;
243 static const int MAX_NUMBER_OF_SOLUTIONS;
244 static const int MAX_PENALTY;
246 static const float BOND_LENGTH_WEIGHTING;
247 static const bool APPLY_FIRST_SOLUTION;
248 };
249
251 {
255 static const String A_STAR;
256
267 static const String ILP;
268
294 static const String FPT;
295
296 static const String K_GREEDY;
298 };
299
301
305
308
309 // constructor with parameter filename //TODO
310 //AssignBondOrderProcessor(const String& file_name);
311
315
319
321 virtual bool start();
322
328 void clear();
329
343 virtual Processor::Result operator ()(AtomContainer& ac);
344
346 virtual bool finish();
347
349
353
363 {
364 if (i >= solutions_.size())
365 {
366 Log.error() << "AssignBondOrderProcessor: No solution with index " << i << std::endl;
367 return 0;
368 }
369 int num_hydrogens = 0;
370
371 HashMap<Atom*, int>::Iterator it = solutions_[i].number_of_virtual_hydrogens.begin();
372 for (; it != solutions_[i].number_of_virtual_hydrogens.end(); it++)
373 num_hydrogens += it->second;
374 return num_hydrogens;
375 }
376
386 Size getNumberOfComputedSolutions() {return solutions_.size();}
387
388
392
395 AtomContainer const* getAtomContainer() const {return ac_;}
396
407
416 {
417 if (i >= solutions_.size())
418 {
419 Log.error() << "AssignBondOrderProcessor: No solution with index " << i << std::endl;
420
421 return std::numeric_limits<float>::max();
422 }
423 else
424 {
425 return getTotalCharge_(solutions_[i]);
426 }
427 }
428
435 {
436 if (i >= solutions_.size())
437 {
438 Log.error() << "AssignBondOrderProcessor: No solution with index " << i << std::endl;
439
440 return std::numeric_limits<float>::max();
441 }
442 else
443 return getTotalPenalty_(solutions_[i]);
444 }
445
446 /* Returns the number of node expansions before solution i was found.
447 *
448 * param i index of the solution, whose number of node expansions should be returned.
449 * return int - number of node expansions before solution i was found.
450 */
452 {
453 if (i >= solutions_.size())
454 {
455 Log.error() << "AssignBondOrderProcessor: No solution with index " << i << std::endl;
456
457 return -1;
458 }
459 else
460 return getNumberOfNodeExpansions_(solutions_[i]);
461 }
462
463 /* Returns the number of node expansions before solution i was found.
464 *
465 * param i index of the solution, whose queue size should be returned.
466 * return int - queue size when solution i was found.
467 */
469 {
470 if (i >= solutions_.size())
471 {
472 Log.error() << "AssignBondOrderProcessor: No solution with index " << i << std::endl;
473
474 return -1;
475 }
476 else
477 return getQueueSize_(solutions_[i]);
478 }
479
493
500
508 bool computeNextSolution(bool apply_solution = true);
509
513
516 bool hasValidOptions(){return readOptions_();}
517
526
532
534
535 protected:
536
543
544
551
561
569
570
587
600
603 //TODO: move to solution!
605
609
610 /* Returns the queue's size at the moment the given solution was found.
611 *
612 * param sol solution, whose queue size should be returned.
613 * return int - queue size when the given solution was found.
614 */
615 int getQueueSize_(const BondOrderAssignment& sol){return sol.getQueueSize();}
616
624 {
625 if (sol.valid)
626 {
627 return sol.total_charge;
628 }
629 else
630 {
631 return 0;
632 }
633 }
634
642 {
643 return sol.coarsePenalty();
644 }
645
646 /* Returns the number of node expansions before the given solution was found.
647 *
648 * param sol solution, whose number of node expansions should be returned.
649 * return int - number of node expansions before solution i was found.
650 */
652
654 bool valid_;
655
658
659 // Map for storing the bonds fixed orders
660 // if a bond is free, the map returns 0
661 std::map<Bond*, short> bond_fixed_;
662
663 // all free bonds in the atom container
664 std::vector<Bond*> free_bonds_;
665
666 // Map for storing the bonds associated index (all bonds)
668
669 // Vector for mapping from variable indices onto bonds (all bonds)
670 std::vector<Bond*> index_to_bond_;
671
672
673
674 // ***************** datastructures for virtual hydrogen bonds ******************
675 //
676 // NOTE: a single virtual bond represents ALL possible hydrogen
677 // bonds for a given atom
678 //
679 // the atoms with upto n possible additional hydrogens
681 //
682 // the max number of virtual hydrogens per virtual bond index
684 //
685 // the number of virtual bonds
687 //
688 // the virtual bond index assigned to this atom!
691 //
692 //
693 // a virtual dummy bond
695
696 // ******************* general datastructures *********************
697
698 // the number of bonds given (free + fixed!)
700
701 // num of free bonds without virtual bonds!
703
704 // store for all atom-indices the atoms fixed valences
705 std::vector<Position> fixed_val_;
706
707 // storing the solutions
708 vector<BondOrderAssignment> solutions_;
709
710 // the original conformation before we computed anything
711 // this is a vector because we can have multiple molecules...
712 vector<BondOrderAssignment> starting_configuration_;
713
714 // the inverse of the atom type penalty normalization factor
716
717 // the inverse of the bond length penalty normalization factor
719
720 // denotes the index of the last applied solution
721 // -1 if there was no valid solution applied
723
724 // the AtomContainer, the processor is operating on
726
727 // max bond order to consider
729
730 // balance parameter between atom type and bond length penalty
731 float alpha_;
732
733 // the max number of solutions to compute
735
736 // the max penalty score
738
739 // flag to indicate, whether also non-optimal solutions should be computed
741
742 // flag for adding missing hydrogens
744
745 // flag for computing also the bond connectivity
747
748 // flag for using fine penalties derived from 3d information
750
751 // //////// general stuff /////////
752
753
754 // The penalty administration datastructures.
755 // filled by readAtomPenalties_
756 // organized in imaginarey blocks of length
757 // block_to_length_[i], starting from
758 // block_to_start_idx_[i] associating
759 // block_to_start_valence_[i] to the start_idx
760 vector<int> penalties_;
761 vector<Position> block_to_start_idx_;
762 vector<Size> block_to_length_;
764 // stores the defining element and the SMART-string of each block
765 vector<std::pair<String, String> > block_definition_;
766
767
768 // Stores which atom belongs to which penalty block.
769 // The first vector element of each atom block denotes the penalty block
770 // assigned to the atom without any additional VIRTUAL Hydrogens,
771 // the second element with one additional Hydrogen and so on.
772 vector< vector<int> > atom_to_block_;
773
774 // Stores the possible bond lengths penalties per order.
776
778
781
782 // The strategies this class can use
784 };
785
786} // namespace BALL
787
788
789#endif // BALL_STRUCTURE_ASSIGNBONDORDERPROCESSOR_H
BALL_EXPORT LogStream Log
LogStream & error(int n=0)
HashMap class based on the STL map (containing serveral convenience functions)
Base::iterator Iterator
Definition hashMap.h:97
Assignment of bond orders from topology information.
bool computeNextSolution(bool apply_solution=true)
virtual ~AssignBondOrderProcessor()
Destructor.
Options options
the processor's options
std::vector< int > virtual_bond_index_to_number_of_virtual_hydrogens_
bool valid_
Processor is in a useable valid state.
const System & getSolution(Position i)
float computeVirtualHydrogens_(Atom *atom)
HashMap< Atom *, int > atom_to_virtual_bond_index_
AssignBondOrderProcessor(const AssignBondOrderProcessor &abop)
HashMap< Atom *, int > number_of_virtual_hydrogens_
int getQueueSize_(const BondOrderAssignment &sol)
float getTotalCharge_(const BondOrderAssignment &sol)
bool apply_(BondOrderAssignment &solution)
int getPenaltyClass_(Atom *atom)
StringHashMap< boost::shared_ptr< BondOrderAssignmentStrategy > > strategies_
float getTotalPenalty_(const BondOrderAssignment &sol)
HashMap< Bond *, vector< float > > bond_lengths_penalties_
AssignBondOrderProcessor()
Default Constructor.
virtual bool finish()
Processor method which is called after the operator()-call.
vector< std::pair< String, String > > block_definition_
vector< BondOrderAssignment > starting_configuration_
float evaluatePenalty(AtomContainer *ac)
int getNumberOfNodeExpansions_(const BondOrderAssignment &sol)
virtual bool start()
Processor method which is called before the operator()-call.
vector< BondOrderAssignment > solutions_
bool evaluation_mode_
Processor is in an evaluation mode. Default is false.
AtomContainer const * getAtomContainer() const
A solution to the bond order assignment problem.
Base class for bond order assignment algorithms.
A full or partial solution to the AStar-based bond order assignment problem.
float coarsePenalty(float atom_type_penalty, float bond_length_penalty) const
#define BALL_EXPORT